Add nullability annotations to smoke-test/spring-boot-smoke-test-websocket-undertow

See gh-46587
This commit is contained in:
Moritz Halbritter 2025-08-12 13:39:59 +02:00
parent 9dc74d5b23
commit 961f8e5e92
9 changed files with 114 additions and 4 deletions

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.websocket.undertow.client;
import org.jspecify.annotations.NullMarked;

View File

@ -16,11 +16,13 @@
package smoketest.websocket.undertow.echo;
import org.jspecify.annotations.Nullable;
public class DefaultEchoService implements EchoService {
private final String echoFormat;
public DefaultEchoService(String echoFormat) {
public DefaultEchoService(@Nullable String echoFormat) {
this.echoFormat = (echoFormat != null) ? echoFormat : "%s";
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.websocket.undertow.echo;
import org.jspecify.annotations.NullMarked;

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.websocket.undertow;
import org.jspecify.annotations.NullMarked;

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.websocket.undertow.reverse;
import org.jspecify.annotations.NullMarked;

View File

@ -16,6 +16,8 @@
package smoketest.websocket.undertow.snake;
import org.jspecify.annotations.Nullable;
public class Location {
/**
@ -44,7 +46,7 @@ public class Location {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}

View File

@ -24,6 +24,7 @@ import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import jakarta.annotation.Nullable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -40,7 +41,7 @@ public final class SnakeTimer {
private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>();
private static Timer gameTimer = null;
private static @Nullable Timer gameTimer;
private SnakeTimer() {
}

View File

@ -21,6 +21,9 @@ import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
@ -34,7 +37,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
private final int id;
private Snake snake;
private @Nullable Snake snake;
public static String getRandomHexColor() {
float hue = random.nextFloat();
@ -79,6 +82,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
Assert.state(this.snake != null, "'snake' must not be null");
String payload = message.getPayload();
switch (payload) {
case "west" -> this.snake.setDirection(Direction.WEST);
@ -90,6 +94,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
Assert.state(this.snake != null, "'snake' must not be null");
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.websocket.undertow.snake;
import org.jspecify.annotations.NullMarked;