Fix overridden methods nullability

Issue: SPR-15869
This commit is contained in:
Sebastien Deleuze
2017-08-17 14:30:14 +02:00
parent 6b6c1d3e53
commit 73cf07e9a4
488 changed files with 1016 additions and 34 deletions

View File

@@ -206,6 +206,7 @@ public class WebSocketHttpHeaders extends HttpHeaders {
* @return the first header value; or {@code null}
*/
@Override
@Nullable
public String getFirst(String headerName) {
return this.headers.getFirst(headerName);
}

View File

@@ -43,7 +43,6 @@ public interface WebSocketSession extends Closeable {
/**
* Return the URI used to open the WebSocket connection.
* ({@code null} on the client side).
*/
@Nullable
URI getUri();

View File

@@ -74,6 +74,7 @@ public abstract class AbstractWebSocketSession<T> implements NativeWebSocketSess
@SuppressWarnings("unchecked")
@Override
@Nullable
public <R> R getNativeSession(@Nullable Class<R> requiredType) {
return (requiredType == null || requiredType.isInstance(this.nativeSession) ? (R) this.nativeSession : null);
}

View File

@@ -40,6 +40,6 @@ public interface NativeWebSocketSession extends WebSocketSession {
* or {@code null} if not available
*/
@Nullable
<T> T getNativeSession(Class<T> requiredType);
<T> T getNativeSession(@Nullable Class<T> requiredType);
}

View File

@@ -102,6 +102,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
}
@Override
@Nullable
public URI getUri() {
checkNativeSessionInitialized();
return this.uri;

View File

@@ -117,6 +117,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
}
@Override
@Nullable
public URI getUri() {
checkNativeSessionInitialized();
return this.uri;

View File

@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.springframework.web.socket.server.support.OriginHandshakeInterceptor;
@@ -56,6 +57,7 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);

View File

@@ -103,6 +103,7 @@ public class WebSocketConfigurationSupport {
private static class NoOpScheduler implements TaskScheduler {
@Override
@Nullable
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
throw new IllegalStateException("Unexpected use of scheduler.");
}

View File

@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketExtension;
@@ -79,6 +80,7 @@ public class WebSocketSessionDecorator implements WebSocketSession {
}
@Override
@Nullable
public URI getUri() {
return this.delegate.getUri();
}

View File

@@ -143,6 +143,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati
// SimpUserRegistry methods
@Override
@Nullable
public SimpUser getUser(String userName) {
return this.users.get(userName);
}
@@ -198,6 +199,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati
}
@Override
@Nullable
public SimpSession getSession(@Nullable String sessionId) {
return (sessionId != null ? this.userSessions.get(sessionId) : null);
}

View File

@@ -57,6 +57,7 @@ public class StompSubProtocolErrorHandler implements SubProtocolErrorHandler<byt
}
@Override
@Nullable
public Message<byte[]> handleErrorMessageToClient(Message<byte[]> errorMessage) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(errorMessage, StompHeaderAccessor.class);
Assert.notNull(accessor, "No StompHeaderAccessor");

View File

@@ -583,6 +583,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
}
@Override
@Nullable
public String resolveSessionId(Message<?> message) {
return SimpMessageHeaderAccessor.getSessionId(message.getHeaders());
}

View File

@@ -103,6 +103,7 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
}
@Override
@Nullable
public Class<?> getBeanType() {
return this.adviceBean.getBeanType();
}

View File

@@ -133,6 +133,7 @@ public class ServletServerContainerFactoryBean
@Override
@Nullable
public ServerContainer getObject() {
return this.serverContainer;
}

View File

@@ -58,6 +58,7 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getNativeSession(@Nullable Class<T> requiredType) {
return (requiredType == null || requiredType.isInstance(this.webSocketSession) ? (T) this.webSocketSession : null);
}

View File

@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -58,11 +59,13 @@ public class Jackson2SockJsMessageCodec extends AbstractSockJsMessageCodec {
@Override
@Nullable
public String[] decode(String content) throws IOException {
return this.objectMapper.readValue(content, String[].class);
}
@Override
@Nullable
public String[] decodeInputStream(InputStream content) throws IOException {
return this.objectMapper.readValue(content, String[].class);
}

View File

@@ -488,6 +488,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
@Override
@Nullable
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
if (!this.suppressCors && CorsUtils.isCorsRequest(request)) {
CorsConfiguration config = new CorsConfiguration();

View File

@@ -27,6 +27,7 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.context.ServletContextAware;
@@ -143,6 +144,7 @@ public class SockJsHttpRequestHandler
}
@Override
@Nullable
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
if (this.sockJsService instanceof CorsConfigurationSource) {
return ((CorsConfigurationSource) this.sockJsService).getCorsConfiguration(request);

View File

@@ -24,6 +24,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler;
@@ -62,6 +63,7 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo
}
@Override
@Nullable
protected String[] readMessages(ServerHttpRequest request) throws IOException {
SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec();
MediaType contentType = request.getHeaders().getContentType();

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.lang.Nullable;
import org.springframework.web.socket.sockjs.transport.TransportHandler;
import org.springframework.web.socket.sockjs.transport.TransportType;
@@ -37,6 +38,7 @@ public class XhrReceivingTransportHandler extends AbstractHttpReceivingTransport
}
@Override
@Nullable
protected String[] readMessages(ServerHttpRequest request) throws IOException {
return getServiceConfig().getMessageCodec().decodeInputStream(request.getBody());
}

View File

@@ -70,6 +70,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
@Override
@Nullable
public URI getUri() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getUri();
@@ -143,7 +144,8 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
}
@Override
public <T> T getNativeSession(Class<T> requiredType) {
@Nullable
public <T> T getNativeSession(@Nullable Class<T> requiredType) {
return (this.webSocketSession instanceof NativeWebSocketSession ?
((NativeWebSocketSession) this.webSocketSession).getNativeSession(requiredType) : null);
}