Nullability fine-tuning around declaration inconsistencies

Issue: SPR-15720
Issue: SPR-15792
This commit is contained in:
Juergen Hoeller
2017-07-19 22:22:14 +02:00
parent 68e6b148cb
commit 46eba3dbfa
186 changed files with 986 additions and 619 deletions

View File

@@ -32,6 +32,7 @@ import org.springframework.util.MimeType;
*/
public class DefaultContentTypeResolver implements ContentTypeResolver {
@Nullable
private MimeType defaultMimeType;
@@ -40,7 +41,7 @@ public class DefaultContentTypeResolver implements ContentTypeResolver {
* {@link MessageHeaders#CONTENT_TYPE} header present.
* <p>This property does not have a default value.
*/
public void setDefaultMimeType(MimeType defaultMimeType) {
public void setDefaultMimeType(@Nullable MimeType defaultMimeType) {
this.defaultMimeType = defaultMimeType;
}
@@ -48,6 +49,7 @@ public class DefaultContentTypeResolver implements ContentTypeResolver {
* Return the default MIME type to use if no
* {@link MessageHeaders#CONTENT_TYPE} header is present.
*/
@Nullable
public MimeType getDefaultMimeType() {
return this.defaultMimeType;
}

View File

@@ -276,6 +276,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
private final boolean throwExceptionOnLateReply;
@Nullable
private volatile Message<?> replyMessage;
private volatile boolean hasReceived;

View File

@@ -283,7 +283,9 @@ public abstract class AbstractBrokerMessageHandler
private class UnsentDisconnectChannelInterceptor extends ChannelInterceptorAdapter {
@Override
public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, Exception ex) {
public void afterSendCompletion(
Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex) {
if (!sent) {
SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
if (SimpMessageType.DISCONNECT.equals(messageType)) {

View File

@@ -548,6 +548,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
}
@Override
@Nullable
public String getReceiptId() {
return this.receiptId;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -256,7 +256,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
}
@Override
public void setDestination(String destination) {
public void setDestination(@Nullable String destination) {
super.setDestination(destination);
setNativeHeader(STOMP_DESTINATION_HEADER, destination);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -18,6 +18,7 @@ package org.springframework.messaging.simp.user;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -195,9 +196,9 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
private static class UserRegistrySnapshot {
private String id;
private String id = "";
private Map<String, TransferSimpUser> users;
private Map<String, TransferSimpUser> users = Collections.emptyMap();
private long expirationTime;
@@ -273,12 +274,12 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
private static class TransferSimpUser implements SimpUser {
private String name;
private String name = "";
/* User sessions from "this" registry only (i.e. one server) */
// User sessions from "this" registry only (i.e. one server)
private Set<TransferSimpSession> sessions;
/* Cross-server session lookup (e.g. user connected to multiple servers) */
// Cross-server session lookup (e.g. user connected to multiple servers)
@Nullable
private SessionLookup sessionLookup;
@@ -393,6 +394,8 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
@SuppressWarnings("unused")
public TransferSimpSession() {
this.id = "";
this.user = new TransferSimpUser();
this.subscriptions = new HashSet<>(4);
}
@@ -401,6 +404,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
public TransferSimpSession(SimpSession session) {
this.id = session.getId();
this.user = new TransferSimpUser();
Set<SimpSubscription> subscriptions = session.getSubscriptions();
this.subscriptions = new HashSet<>(subscriptions.size());
for (SimpSubscription subscription : subscriptions) {
@@ -443,12 +447,12 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
@Override
public boolean equals(Object other) {
return (this == other || (other instanceof SimpSession && this.id.equals(((SimpSession) other).getId())));
return (this == other || (other instanceof SimpSession && getId().equals(((SimpSession) other).getId())));
}
@Override
public int hashCode() {
return this.id.hashCode();
return getId().hashCode();
}
@Override
@@ -474,6 +478,9 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
@SuppressWarnings("unused")
public TransferSimpSubscription() {
this.id = "";
this.session = new TransferSimpSession();
this.destination = "";
}
/**
@@ -481,6 +488,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
*/
public TransferSimpSubscription(SimpSubscription subscription) {
this.id = subscription.getId();
this.session = new TransferSimpSession();
this.destination = subscription.getDestination();
}
@@ -520,13 +528,13 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
return false;
}
SimpSubscription otherSubscription = (SimpSubscription) other;
return (ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession()) &&
this.id.equals(otherSubscription.getId()));
return (getId().equals(otherSubscription.getId()) &&
ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession()));
}
@Override
public int hashCode() {
return this.id.hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
return getId().hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -18,6 +18,8 @@ package org.springframework.messaging.simp.user;
import java.util.Set;
import org.springframework.lang.Nullable;
/**
* Represents a session of connected user.
*

View File

@@ -16,6 +16,8 @@
package org.springframework.messaging.simp.user;
import org.springframework.lang.Nullable;
/**
* Represents a subscription within a user session.
*
@@ -25,17 +27,17 @@ package org.springframework.messaging.simp.user;
public interface SimpSubscription {
/**
* Return the id associated of the subscription (never {@code null}).
* Return the id associated of the subscription.
*/
String getId();
/**
* Return the session of the subscription (never {@code null}).
* Return the session of the subscription.
*/
SimpSession getSession();
/**
* Return the subscription's destination (never {@code null}).
* Return the subscription's destination.
*/
String getDestination();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.messaging.support;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
@@ -39,7 +40,7 @@ public abstract class ChannelInterceptorAdapter implements ChannelInterceptor {
}
@Override
public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, Exception ex) {
public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex) {
}
public boolean preReceive(MessageChannel channel) {
@@ -52,7 +53,7 @@ public abstract class ChannelInterceptorAdapter implements ChannelInterceptor {
}
@Override
public void afterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex) {
public void afterReceiveCompletion(@Nullable Message<?> message, MessageChannel channel, @Nullable Exception ex) {
}
}