Switch to JSpecify annotations

This commit updates the whole Spring Framework codebase to use JSpecify
annotations instead of Spring null-safety annotations with JSR 305
semantics.

JSpecify provides signficant enhancements such as properly defined
specifications, a canonical dependency with no split-package issue,
better tooling, better Kotlin integration and the capability to specify
generic type, array and varargs element null-safety. Generic type
null-safety is not defined by this commit yet and will be specified
later.

A key difference is that Spring null-safety annotations, following
JSR 305 semantics, apply to fields, parameters and return values,
while JSpecify annotations apply to type usages. That's why this
commit moves nullability annotations closer to the type for fields
and return values.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 15:22:37 +01:00
parent fcb8aed03f
commit bc5d771a06
3459 changed files with 14118 additions and 22059 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.messaging;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Exception that indicates an error occurred during message delivery.

View File

@@ -30,8 +30,8 @@ import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.CollectionUtils;
import org.springframework.util.IdGenerator;
@@ -112,8 +112,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator();
@Nullable
private static volatile IdGenerator idGenerator;
private static volatile @Nullable IdGenerator idGenerator;
@SuppressWarnings("serial")
private final Map<String, Object> headers;
@@ -183,30 +182,25 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
return (generator != null ? generator : defaultIdGenerator);
}
@Nullable
public UUID getId() {
public @Nullable UUID getId() {
return get(ID, UUID.class);
}
@Nullable
public Long getTimestamp() {
public @Nullable Long getTimestamp() {
return get(TIMESTAMP, Long.class);
}
@Nullable
public Object getReplyChannel() {
public @Nullable Object getReplyChannel() {
return get(REPLY_CHANNEL);
}
@Nullable
public Object getErrorChannel() {
public @Nullable Object getErrorChannel() {
return get(ERROR_CHANNEL);
}
@SuppressWarnings("unchecked")
@Nullable
public <T> T get(Object key, Class<T> type) {
public <T> @Nullable T get(Object key, Class<T> type) {
Object value = this.headers.get(key);
if (value == null) {
return null;
@@ -237,8 +231,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
}
@Override
@Nullable
public Object get(Object key) {
public @Nullable Object get(Object key) {
return this.headers.get(key);
}

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging;
import org.jspecify.annotations.Nullable;
import org.springframework.core.NestedRuntimeException;
import org.springframework.lang.Nullable;
/**
* The base exception for any failures related to messaging.
@@ -29,8 +30,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class MessagingException extends NestedRuntimeException {
@Nullable
private final Message<?> failedMessage;
private final @Nullable Message<?> failedMessage;
public MessagingException(Message<?> message) {
@@ -64,8 +64,7 @@ public class MessagingException extends NestedRuntimeException {
}
@Nullable
public Message<?> getFailedMessage() {
public @Nullable Message<?> getFailedMessage() {
return this.failedMessage;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.messaging;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* A {@link MessageChannel} from which messages may be actively received through polling.
@@ -30,8 +30,7 @@ public interface PollableChannel extends MessageChannel {
* Receive a message from this channel, blocking indefinitely if necessary.
* @return the next available {@link Message} or {@code null} if interrupted
*/
@Nullable
Message<?> receive();
@Nullable Message<?> receive();
/**
* Receive a message from this channel, blocking until either a message is available
@@ -40,7 +39,6 @@ public interface PollableChannel extends MessageChannel {
* @return the next available {@link Message} or {@code null} if the specified timeout
* period elapses or the message receipt is interrupted
*/
@Nullable
Message<?> receive(long timeout);
@Nullable Message<?> receive(long timeout);
}

View File

@@ -28,7 +28,8 @@ import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.ClassUtils;
@@ -62,8 +63,7 @@ public abstract class AbstractJsonMessageConverter extends AbstractMessageConver
}
@Override
@Nullable
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
try {
Type resolvedType = getResolvedType(targetClass, conversionHint);
Object payload = message.getPayload();
@@ -84,8 +84,7 @@ public abstract class AbstractJsonMessageConverter extends AbstractMessageConver
}
@Override
@Nullable
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
try {
Type resolvedType = getResolvedType(payload.getClass(), conversionHint);
if (byte[].class == getSerializedPayloadClass()) {

View File

@@ -25,10 +25,10 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
@@ -53,8 +53,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
private final List<MimeType> supportedMimeTypes = new ArrayList<>(4);
@Nullable
private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
private @Nullable ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
private boolean strictContentTypeMatch = false;
@@ -116,8 +115,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
* Return the {@link #setContentTypeResolver(ContentTypeResolver) configured}
* {@code ContentTypeResolver}.
*/
@Nullable
public ContentTypeResolver getContentTypeResolver() {
public @Nullable ContentTypeResolver getContentTypeResolver() {
return this.contentTypeResolver;
}
@@ -169,14 +167,12 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
@Override
@Nullable
public final Object fromMessage(Message<?> message, Class<?> targetClass) {
public final @Nullable Object fromMessage(Message<?> message, Class<?> targetClass) {
return fromMessage(message, targetClass, null);
}
@Override
@Nullable
public final Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
public final @Nullable Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
if (!canConvertFrom(message, targetClass)) {
return null;
}
@@ -184,14 +180,12 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
}
@Override
@Nullable
public final Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
public final @Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
return toMessage(payload, headers, null);
}
@Override
@Nullable
public final Message<?> toMessage(
public final @Nullable Message<?> toMessage(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
if (!canConvertTo(payload, headers)) {
@@ -249,8 +243,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
return false;
}
@Nullable
protected MimeType getMimeType(@Nullable MessageHeaders headers) {
protected @Nullable MimeType getMimeType(@Nullable MessageHeaders headers) {
return (this.contentTypeResolver != null ? this.contentTypeResolver.resolve(headers) : null);
}
@@ -264,8 +257,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
* @param payload the payload being converted to a message
* @return the content type, or {@code null} if not known
*/
@Nullable
protected MimeType getDefaultContentType(Object payload) {
protected @Nullable MimeType getDefaultContentType(Object payload) {
List<MimeType> mimeTypes = getSupportedMimeTypes();
return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null);
}
@@ -288,8 +280,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
* perform the conversion
* @since 4.2
*/
@Nullable
protected Object convertFromInternal(
protected @Nullable Object convertFromInternal(
Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
return null;
@@ -305,8 +296,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
* cannot perform the conversion
* @since 4.2
*/
@Nullable
protected Object convertToInternal(
protected @Nullable Object convertToInternal(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
return null;

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.MimeTypeUtils;
@@ -41,16 +42,14 @@ public class ByteArrayMessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertFromInternal(
protected @Nullable Object convertFromInternal(
Message<?> message, @Nullable Class<?> targetClass, @Nullable Object conversionHint) {
return message.getPayload();
}
@Override
@Nullable
protected Object convertToInternal(
protected @Nullable Object convertToInternal(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
return payload;

View File

@@ -20,7 +20,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
@@ -51,8 +52,7 @@ public class CompositeMessageConverter implements SmartMessageConverter {
@Override
@Nullable
public Object fromMessage(Message<?> message, Class<?> targetClass) {
public @Nullable Object fromMessage(Message<?> message, Class<?> targetClass) {
for (MessageConverter converter : getConverters()) {
Object result = converter.fromMessage(message, targetClass);
if (result != null) {
@@ -63,8 +63,7 @@ public class CompositeMessageConverter implements SmartMessageConverter {
}
@Override
@Nullable
public Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
public @Nullable Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
for (MessageConverter converter : getConverters()) {
Object result = (converter instanceof SmartMessageConverter smartMessageConverter ?
smartMessageConverter.fromMessage(message, targetClass, conversionHint) :
@@ -77,8 +76,7 @@ public class CompositeMessageConverter implements SmartMessageConverter {
}
@Override
@Nullable
public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
public @Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
for (MessageConverter converter : getConverters()) {
Message<?> result = converter.toMessage(payload, headers);
if (result != null) {
@@ -89,8 +87,7 @@ public class CompositeMessageConverter implements SmartMessageConverter {
}
@Override
@Nullable
public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
public @Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
for (MessageConverter converter : getConverters()) {
Message<?> result = (converter instanceof SmartMessageConverter smartMessageConverter ?
smartMessageConverter.toMessage(payload, headers, conversionHint) :

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.InvalidMimeTypeException;
import org.springframework.util.MimeType;
@@ -37,7 +38,6 @@ public interface ContentTypeResolver {
* @throws InvalidMimeTypeException if the content type is a String that cannot be parsed
* @throws IllegalArgumentException if there is a content type but its type is unknown
*/
@Nullable
MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException;
@Nullable MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException;
}

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.MimeType;
@@ -32,8 +33,7 @@ import org.springframework.util.MimeType;
*/
public class DefaultContentTypeResolver implements ContentTypeResolver {
@Nullable
private MimeType defaultMimeType;
private @Nullable MimeType defaultMimeType;
/**
@@ -49,15 +49,13 @@ 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() {
public @Nullable MimeType getDefaultMimeType() {
return this.defaultMimeType;
}
@Override
@Nullable
public MimeType resolve(@Nullable MessageHeaders headers) {
public @Nullable MimeType resolve(@Nullable MessageHeaders headers) {
if (headers == null || headers.get(MessageHeaders.CONTENT_TYPE) == null) {
return this.defaultMimeType;
}

View File

@@ -16,10 +16,11 @@
package org.springframework.messaging.converter;
import org.jspecify.annotations.Nullable;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -58,8 +59,7 @@ public class GenericMessageConverter extends SimpleMessageConverter {
@Override
@Nullable
public Object fromMessage(Message<?> message, Class<?> targetClass) {
public @Nullable Object fromMessage(Message<?> message, Class<?> targetClass) {
Object payload = message.getPayload();
if (this.conversionService.canConvert(payload.getClass(), targetClass)) {
try {

View File

@@ -34,9 +34,9 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
@@ -64,8 +64,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
private ObjectMapper objectMapper;
@Nullable
private Boolean prettyPrint;
private @Nullable Boolean prettyPrint;
/**
@@ -227,8 +226,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
JavaType javaType = this.objectMapper.constructType(getResolvedType(targetClass, conversionHint));
Object payload = message.getPayload();
Class<?> view = getSerializationView(conversionHint);
@@ -260,8 +258,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
@Nullable Object conversionHint) {
try {
@@ -304,8 +301,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
* @return the serialization view class, or {@code null} if none
* @since 4.2
*/
@Nullable
protected Class<?> getSerializationView(@Nullable Object conversionHint) {
protected @Nullable Class<?> getSerializationView(@Nullable Object conversionHint) {
if (conversionHint instanceof MethodParameter param) {
JsonView annotation = (param.getParameterIndex() >= 0 ?
param.getParameterAnnotation(JsonView.class) : param.getMethodAnnotation(JsonView.class));

View File

@@ -27,8 +27,9 @@ import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.TypeMismatchException;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.oxm.Marshaller;
@@ -51,11 +52,9 @@ import org.springframework.util.MimeType;
*/
public class MarshallingMessageConverter extends AbstractMessageConverter {
@Nullable
private Marshaller marshaller;
private @Nullable Marshaller marshaller;
@Nullable
private Unmarshaller unmarshaller;
private @Nullable Unmarshaller unmarshaller;
/**
@@ -102,8 +101,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
/**
* Return the configured Marshaller.
*/
@Nullable
public Marshaller getMarshaller() {
public @Nullable Marshaller getMarshaller() {
return this.marshaller;
}
@@ -117,8 +115,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
/**
* Return the configured unmarshaller.
*/
@Nullable
public Unmarshaller getUnmarshaller() {
public @Nullable Unmarshaller getUnmarshaller() {
return this.unmarshaller;
}
@@ -142,8 +139,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
Assert.state(this.unmarshaller != null, "Property 'unmarshaller' is required");
try {
Source source = getSource(message.getPayload());
@@ -168,8 +164,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
@Nullable Object conversionHint) {
Assert.state(this.marshaller != null, "Property 'marshaller' is required");

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
@@ -42,8 +43,7 @@ public interface MessageConverter {
* @return the result of the conversion, or {@code null} if the converter cannot
* perform the conversion
*/
@Nullable
Object fromMessage(Message<?> message, Class<?> targetClass);
@Nullable Object fromMessage(Message<?> message, Class<?> targetClass);
/**
* Create a {@link Message} whose payload is the result of converting the given
@@ -58,7 +58,6 @@ public interface MessageConverter {
* @return the new message, or {@code null} if the converter does not support the
* Object type or the target media type
*/
@Nullable
Message<?> toMessage(Object payload, @Nullable MessageHeaders headers);
@Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers);
}

View File

@@ -18,8 +18,7 @@ package org.springframework.messaging.converter;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.util.JsonFormat;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Subclass of {@link ProtobufMessageConverter} for use with the official
@@ -52,7 +51,7 @@ public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter
* JsonFormat.Printer}, and a default instance of {@link ExtensionRegistry}.
*/
public ProtobufJsonFormatMessageConverter(
@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
JsonFormat.@Nullable Parser parser, JsonFormat.@Nullable Printer printer) {
this(parser, printer, null);
}
@@ -62,8 +61,8 @@ public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter
* JsonFormat.Parser}, {@link com.google.protobuf.util.JsonFormat.Printer
* JsonFormat.Printer}, and {@link ExtensionRegistry}.
*/
public ProtobufJsonFormatMessageConverter(@Nullable JsonFormat.Parser parser,
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) {
public ProtobufJsonFormatMessageConverter(JsonFormat.@Nullable Parser parser,
JsonFormat.@Nullable Printer printer, @Nullable ExtensionRegistry extensionRegistry) {
super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry);
}

View File

@@ -28,8 +28,8 @@ import java.util.Map;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.util.JsonFormat;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
@@ -75,8 +75,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter {
final ExtensionRegistry extensionRegistry;
@Nullable
private final ProtobufFormatSupport protobufFormatSupport;
private final @Nullable ProtobufFormatSupport protobufFormatSupport;
/**
@@ -244,7 +243,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter {
private final JsonFormat.Printer printer;
public ProtobufJavaUtilSupport(@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
public ProtobufJavaUtilSupport(JsonFormat.@Nullable Parser parser, JsonFormat.@Nullable Printer printer) {
this.parser = (parser != null ? parser : JsonFormat.parser());
this.printer = (printer != null ? printer : JsonFormat.printer());
}

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
@@ -36,8 +37,7 @@ import org.springframework.util.ClassUtils;
public class SimpleMessageConverter implements MessageConverter {
@Override
@Nullable
public Object fromMessage(Message<?> message, Class<?> targetClass) {
public @Nullable Object fromMessage(Message<?> message, Class<?> targetClass) {
Object payload = message.getPayload();
return (ClassUtils.isAssignableValue(targetClass, payload) ? payload : null);
}

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.converter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
@@ -44,8 +45,7 @@ public interface SmartMessageConverter extends MessageConverter {
* perform the conversion
* @see #fromMessage(Message, Class)
*/
@Nullable
Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint);
@Nullable Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint);
/**
* A variant of {@link #toMessage(Object, MessageHeaders)} which takes an extra
@@ -59,7 +59,6 @@ public interface SmartMessageConverter extends MessageConverter {
* Object type or the target media type
* @see #toMessage(Object, MessageHeaders)
*/
@Nullable
Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint);
@Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint);
}

View File

@@ -19,7 +19,8 @@ package org.springframework.messaging.converter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
@@ -61,8 +62,7 @@ public class StringMessageConverter extends AbstractMessageConverter {
}
@Override
@Nullable
protected Object convertToInternal(
protected @Nullable Object convertToInternal(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
if (byte[].class == getSerializedPayloadClass()) {

View File

@@ -1,9 +1,7 @@
/**
* Provides support for message conversion.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.converter;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -42,8 +43,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
DestinationResolvingMessageReceivingOperations<D>,
DestinationResolvingMessageRequestReplyOperations<D> {
@Nullable
private DestinationResolver<D> destinationResolver;
private @Nullable DestinationResolver<D> destinationResolver;
/**
@@ -60,8 +60,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
/**
* Return the configured destination resolver.
*/
@Nullable
public DestinationResolver<D> getDestinationResolver() {
public @Nullable DestinationResolver<D> getDestinationResolver() {
return this.destinationResolver;
}
@@ -102,36 +101,31 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
}
@Override
@Nullable
public Message<?> receive(String destinationName) {
public @Nullable Message<?> receive(String destinationName) {
D destination = resolveDestination(destinationName);
return super.receive(destination);
}
@Override
@Nullable
public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) {
public <T> @Nullable T receiveAndConvert(String destinationName, Class<T> targetClass) {
D destination = resolveDestination(destinationName);
return super.receiveAndConvert(destination, targetClass);
}
@Override
@Nullable
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) {
public @Nullable Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) {
D destination = resolveDestination(destinationName);
return super.sendAndReceive(destination, requestMessage);
}
@Override
@Nullable
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) {
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) {
D destination = resolveDestination(destinationName);
return super.convertSendAndReceive(destination, request, targetClass);
}
@Override
@Nullable
public <T> T convertSendAndReceive(String destinationName, Object request,
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request,
@Nullable Map<String, Object> headers, Class<T> targetClass) {
D destination = resolveDestination(destinationName);
@@ -139,8 +133,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
}
@Override
@Nullable
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
@Nullable MessagePostProcessor postProcessor) {
D destination = resolveDestination(destinationName);
@@ -148,8 +141,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
}
@Override
@Nullable
public <T> T convertSendAndReceive(String destinationName, Object request,
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request,
@Nullable Map<String, Object> headers, Class<T> targetClass,
@Nullable MessagePostProcessor postProcessor) {

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
@@ -35,14 +36,12 @@ public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessag
implements MessageReceivingOperations<D> {
@Override
@Nullable
public Message<?> receive() {
public @Nullable Message<?> receive() {
return doReceive(getRequiredDefaultDestination());
}
@Override
@Nullable
public Message<?> receive(D destination) {
public @Nullable Message<?> receive(D destination) {
return doReceive(destination);
}
@@ -52,19 +51,16 @@ public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessag
* @return the received message, possibly {@code null} if the message could not
* be received, for example due to a timeout
*/
@Nullable
protected abstract Message<?> doReceive(D destination);
protected abstract @Nullable Message<?> doReceive(D destination);
@Override
@Nullable
public <T> T receiveAndConvert(Class<T> targetClass) {
public <T> @Nullable T receiveAndConvert(Class<T> targetClass) {
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
}
@Override
@Nullable
public <T> T receiveAndConvert(D destination, Class<T> targetClass) {
public <T> @Nullable T receiveAndConvert(D destination, Class<T> targetClass) {
Message<?> message = doReceive(destination);
if (message != null) {
return doConvert(message, targetClass);
@@ -81,8 +77,7 @@ public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessag
* @return the converted payload of the reply message (never {@code null})
*/
@SuppressWarnings("unchecked")
@Nullable
protected <T> T doConvert(Message<?> message, Class<T> targetClass) {
protected <T> @Nullable T doConvert(Message<?> message, Class<T> targetClass) {
MessageConverter messageConverter = getMessageConverter();
T value = (T) messageConverter.fromMessage(message, targetClass);
if (value == null) {

View File

@@ -20,8 +20,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
@@ -53,8 +53,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private D defaultDestination;
private @Nullable D defaultDestination;
private MessageConverter converter = new SimpleMessageConverter();
@@ -71,8 +70,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
/**
* Return the configured default destination.
*/
@Nullable
public D getDefaultDestination() {
public @Nullable D getDefaultDestination() {
return this.defaultDestination;
}
@@ -194,8 +192,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
* @param headers the headers to send (or {@code null} if none)
* @return the actual headers to send (or {@code null} if none)
*/
@Nullable
protected Map<String, Object> processHeadersToSend(@Nullable Map<String, Object> headers) {
protected @Nullable Map<String, Object> processHeadersToSend(@Nullable Map<String, Object> headers) {
return headers;
}

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
/**
@@ -35,52 +36,44 @@ public abstract class AbstractMessagingTemplate<D> extends AbstractMessageReceiv
implements MessageRequestReplyOperations<D> {
@Override
@Nullable
public Message<?> sendAndReceive(Message<?> requestMessage) {
public @Nullable Message<?> sendAndReceive(Message<?> requestMessage) {
return sendAndReceive(getRequiredDefaultDestination(), requestMessage);
}
@Override
@Nullable
public Message<?> sendAndReceive(D destination, Message<?> requestMessage) {
public @Nullable Message<?> sendAndReceive(D destination, Message<?> requestMessage) {
return doSendAndReceive(destination, requestMessage);
}
@Nullable
protected abstract Message<?> doSendAndReceive(D destination, Message<?> requestMessage);
protected abstract @Nullable Message<?> doSendAndReceive(D destination, Message<?> requestMessage);
@Override
@Nullable
public <T> T convertSendAndReceive(Object request, Class<T> targetClass) {
public <T> @Nullable T convertSendAndReceive(Object request, Class<T> targetClass) {
return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass);
}
@Override
@Nullable
public <T> T convertSendAndReceive(D destination, Object request, Class<T> targetClass) {
public <T> @Nullable T convertSendAndReceive(D destination, Object request, Class<T> targetClass) {
return convertSendAndReceive(destination, request, null, targetClass);
}
@Override
@Nullable
public <T> T convertSendAndReceive(
public <T> @Nullable T convertSendAndReceive(
D destination, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass) {
return convertSendAndReceive(destination, request, headers, targetClass, null);
}
@Override
@Nullable
public <T> T convertSendAndReceive(
public <T> @Nullable T convertSendAndReceive(
Object request, Class<T> targetClass, @Nullable MessagePostProcessor postProcessor) {
return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass, postProcessor);
}
@Override
@Nullable
public <T> T convertSendAndReceive(D destination, Object request, Class<T> targetClass,
public <T> @Nullable T convertSendAndReceive(D destination, Object request, Class<T> targetClass,
@Nullable MessagePostProcessor postProcessor) {
return convertSendAndReceive(destination, request, null, targetClass, postProcessor);
@@ -88,8 +81,7 @@ public abstract class AbstractMessagingTemplate<D> extends AbstractMessageReceiv
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T convertSendAndReceive(D destination, Object request, @Nullable Map<String, Object> headers,
public <T> @Nullable T convertSendAndReceive(D destination, Object request, @Nullable Map<String, Object> headers,
Class<T> targetClass, @Nullable MessagePostProcessor postProcessor) {
Message<?> requestMessage = doConvert(request, headers, postProcessor);

View File

@@ -16,10 +16,11 @@
package org.springframework.messaging.core;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.util.Assert;
@@ -34,8 +35,7 @@ import org.springframework.util.Assert;
public class BeanFactoryMessageChannelDestinationResolver
implements DestinationResolver<MessageChannel>, BeanFactoryAware {
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
/**

View File

@@ -19,8 +19,9 @@ package org.springframework.messaging.core;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -39,8 +40,7 @@ public class CachingDestinationResolverProxy<D> implements DestinationResolver<D
private final Map<String, D> resolvedDestinationCache = new ConcurrentHashMap<>();
@Nullable
private DestinationResolver<D> targetDestinationResolver;
private @Nullable DestinationResolver<D> targetDestinationResolver;
/**

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.MessagingException;
/**

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
@@ -36,8 +37,7 @@ public interface DestinationResolvingMessageReceivingOperations<D> extends Messa
* Resolve the given destination name and receive a message from it.
* @param destinationName the destination name to resolve
*/
@Nullable
Message<?> receive(String destinationName) throws MessagingException;
@Nullable Message<?> receive(String destinationName) throws MessagingException;
/**
* Resolve the given destination name, receive a message from it,
@@ -45,7 +45,6 @@ public interface DestinationResolvingMessageReceivingOperations<D> extends Messa
* @param destinationName the destination name to resolve
* @param targetClass the target class for the converted payload
*/
@Nullable
<T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException;
<T> @Nullable T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException;
}

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
@@ -42,8 +43,7 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> extends Me
* @return the received message, possibly {@code null} if the message could not
* be received, for example due to a timeout
*/
@Nullable
Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException;
@Nullable Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException;
/**
* Resolve the given destination name, convert the payload request Object
@@ -57,8 +57,7 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> extends Me
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
<T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
throws MessagingException;
/**
@@ -74,8 +73,7 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> extends Me
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(String destinationName, Object request,
<T> @Nullable T convertSendAndReceive(String destinationName, Object request,
@Nullable Map<String, Object> headers, Class<T> targetClass) throws MessagingException;
/**
@@ -92,8 +90,7 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> extends Me
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
<T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
@Nullable MessagePostProcessor requestPostProcessor) throws MessagingException;
/**
@@ -111,8 +108,7 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> extends Me
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers,
<T> @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers,
Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException;
}

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;

View File

@@ -21,11 +21,11 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
@@ -193,13 +193,11 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
}
@Override
@Nullable
protected final Message<?> doReceive(MessageChannel channel) {
protected final @Nullable Message<?> doReceive(MessageChannel channel) {
return doReceive(channel, this.receiveTimeout);
}
@Nullable
protected final Message<?> doReceive(MessageChannel channel, long timeout) {
protected final @Nullable Message<?> doReceive(MessageChannel channel, long timeout) {
Assert.notNull(channel, "MessageChannel is required");
if (!(channel instanceof PollableChannel pollableChannel)) {
throw new IllegalStateException("A PollableChannel is required to receive messages");
@@ -215,8 +213,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
}
@Override
@Nullable
protected final Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage) {
protected final @Nullable Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage) {
Assert.notNull(channel, "'channel' is required");
Object originalReplyChannelHeader = requestMessage.getHeaders().getReplyChannel();
Object originalErrorChannelHeader = requestMessage.getHeaders().getErrorChannel();
@@ -259,8 +256,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
return (receiveTimeout != null ? receiveTimeout : this.receiveTimeout);
}
@Nullable
private Long headerToLong(@Nullable Object headerValue) {
private @Nullable Long headerToLong(@Nullable Object headerValue) {
if (headerValue instanceof Number number) {
return number.longValue();
}
@@ -284,8 +280,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
private final boolean throwExceptionOnLateReply;
@Nullable
private volatile Message<?> replyMessage;
private volatile @Nullable Message<?> replyMessage;
private volatile boolean hasReceived;
@@ -302,14 +297,12 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
}
@Override
@Nullable
public Message<?> receive() {
public @Nullable Message<?> receive() {
return this.receive(-1);
}
@Override
@Nullable
public Message<?> receive(long timeout) {
public @Nullable Message<?> receive(long timeout) {
try {
if (timeout < 0) {
this.replyLatch.await();

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
@@ -36,8 +37,7 @@ public interface MessageReceivingOperations<D> {
* @return the received message, possibly {@code null} if the message could not
* be received, for example due to a timeout
*/
@Nullable
Message<?> receive() throws MessagingException;
@Nullable Message<?> receive() throws MessagingException;
/**
* Receive a message from the given destination.
@@ -45,8 +45,7 @@ public interface MessageReceivingOperations<D> {
* @return the received message, possibly {@code null} if the message could not
* be received, for example due to a timeout
*/
@Nullable
Message<?> receive(D destination) throws MessagingException;
@Nullable Message<?> receive(D destination) throws MessagingException;
/**
* Receive a message from a default destination and convert its payload to the
@@ -55,8 +54,7 @@ public interface MessageReceivingOperations<D> {
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T receiveAndConvert(Class<T> targetClass) throws MessagingException;
<T> @Nullable T receiveAndConvert(Class<T> targetClass) throws MessagingException;
/**
* Receive a message from the given destination and convert its payload to the
@@ -66,7 +64,6 @@ public interface MessageReceivingOperations<D> {
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@Nullable
<T> T receiveAndConvert(D destination, Class<T> targetClass) throws MessagingException;
<T> @Nullable T receiveAndConvert(D destination, Class<T> targetClass) throws MessagingException;
}

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
@@ -39,8 +40,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the reply, possibly {@code null} if the message could not be received,
* for example due to a timeout
*/
@Nullable
Message<?> sendAndReceive(Message<?> requestMessage) throws MessagingException;
@Nullable Message<?> sendAndReceive(Message<?> requestMessage) throws MessagingException;
/**
* Send a request message and receive the reply from the given destination.
@@ -49,8 +49,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the reply, possibly {@code null} if the message could not be received,
* for example due to a timeout
*/
@Nullable
Message<?> sendAndReceive(D destination, Message<?> requestMessage) throws MessagingException;
@Nullable Message<?> sendAndReceive(D destination, Message<?> requestMessage) throws MessagingException;
/**
* Convert the given request Object to serialized form, possibly using a
@@ -62,8 +61,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(Object request, Class<T> targetClass) throws MessagingException;
<T> @Nullable T convertSendAndReceive(Object request, Class<T> targetClass) throws MessagingException;
/**
* Convert the given request Object to serialized form, possibly using a
@@ -76,8 +74,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(D destination, Object request, Class<T> targetClass) throws MessagingException;
<T> @Nullable T convertSendAndReceive(D destination, Object request, Class<T> targetClass) throws MessagingException;
/**
* Convert the given request Object to serialized form, possibly using a
@@ -91,8 +88,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(
<T> @Nullable T convertSendAndReceive(
D destination, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass)
throws MessagingException;
@@ -108,8 +104,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(
<T> @Nullable T convertSendAndReceive(
Object request, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor)
throws MessagingException;
@@ -126,8 +121,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(D destination, Object request, Class<T> targetClass,
<T> @Nullable T convertSendAndReceive(D destination, Object request, Class<T> targetClass,
MessagePostProcessor requestPostProcessor) throws MessagingException;
/**
@@ -143,8 +137,7 @@ public interface MessageRequestReplyOperations<D> {
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@Nullable
<T> T convertSendAndReceive(
<T> @Nullable T convertSendAndReceive(
D destination, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass,
@Nullable MessagePostProcessor requestPostProcessor) throws MessagingException;

View File

@@ -18,7 +18,8 @@ package org.springframework.messaging.core;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;

View File

@@ -1,9 +1,7 @@
/**
* Defines interfaces and implementation classes for messaging templates.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.core;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,7 +19,7 @@ package org.springframework.messaging.handler;
import java.util.Collection;
import java.util.StringJoiner;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Base class for {@code MessageCondition's} that pre-declares abstract methods

View File

@@ -21,7 +21,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -80,8 +81,7 @@ public class CompositeMessageCondition implements MessageCondition<CompositeMess
}
@Override
@Nullable
public CompositeMessageCondition getMatchingCondition(Message<?> message) {
public @Nullable CompositeMessageCondition getMatchingCondition(Message<?> message) {
List<MessageCondition<?>> result = new ArrayList<>(this.messageConditions.size());
for (MessageCondition<?> condition : this.messageConditions) {
MessageCondition<?> matchingCondition = (MessageCondition<?>) condition.getMatchingCondition(message);

View File

@@ -25,7 +25,8 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.CollectionUtils;
@@ -160,8 +161,7 @@ public class DestinationPatternsMessageCondition
* or {@code null} either if a destination can not be extracted or there is no match
*/
@Override
@Nullable
public DestinationPatternsMessageCondition getMatchingCondition(Message<?> message) {
public @Nullable DestinationPatternsMessageCondition getMatchingCondition(Message<?> message) {
Object destination = message.getHeaders().get(LOOKUP_DESTINATION_HEADER);
if (destination == null) {
return null;

View File

@@ -22,10 +22,10 @@ import java.util.stream.IntStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.annotation.AnnotatedMethod;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -53,13 +53,11 @@ public class HandlerMethod extends AnnotatedMethod {
private final Object bean;
@Nullable
private final BeanFactory beanFactory;
private final @Nullable BeanFactory beanFactory;
private final Class<?> beanType;
@Nullable
private HandlerMethod resolvedFromHandlerMethod;
private @Nullable HandlerMethod resolvedFromHandlerMethod;
protected Log logger = defaultLogger;
@@ -167,8 +165,7 @@ public class HandlerMethod extends AnnotatedMethod {
* resolved via {@link #createWithResolvedBean()}.
* @since 4.3
*/
@Nullable
public HandlerMethod getResolvedFromHandlerMethod() {
public @Nullable HandlerMethod getResolvedFromHandlerMethod() {
return this.resolvedFromHandlerMethod;
}
@@ -215,7 +212,7 @@ public class HandlerMethod extends AnnotatedMethod {
* beans, and others). Endpoint classes that require proxying should prefer
* class-based proxy mechanisms.
*/
protected void assertTargetBean(Method method, Object targetBean, Object[] args) {
protected void assertTargetBean(Method method, Object targetBean, @Nullable Object[] args) {
Class<?> methodDeclaringClass = method.getDeclaringClass();
Class<?> targetBeanClass = targetBean.getClass();
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
@@ -227,7 +224,7 @@ public class HandlerMethod extends AnnotatedMethod {
}
}
protected String formatInvokeError(String text, Object[] args) {
protected String formatInvokeError(String text, @Nullable Object[] args) {
String formattedArgs = IntStream.range(0, args.length)
.mapToObj(i -> (args[i] != null ?
"[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :

View File

@@ -16,7 +16,8 @@
package org.springframework.messaging.handler;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message;
/**
@@ -47,8 +48,7 @@ public interface MessageCondition<T> {
* condition with sorted, matching patterns only.
* @return a condition instance in case of a match; or {@code null} if there is no match.
*/
@Nullable
T getMatchingCondition(Message<?> message);
@Nullable T getMatchingCondition(Message<?> message);
/**
* Compare this condition to another in the context of a specific message.

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler;
import org.jspecify.annotations.Nullable;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
/**
* Represents a Spring-managed bean with cross-cutting functionality to be
@@ -40,8 +41,7 @@ public interface MessagingAdviceBean extends Ordered {
* <p>If the bean type is a CGLIB-generated class, the original user-defined
* class is returned.
*/
@Nullable
Class<?> getBeanType();
@Nullable Class<?> getBeanType();
/**
* Return the advice bean instance, if necessary resolving a bean specified

View File

@@ -22,12 +22,13 @@ import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.security.Principal;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.ReflectionHints;
import org.springframework.aot.hint.annotation.ReflectiveProcessor;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageHeaderAccessor;
@@ -114,8 +115,7 @@ public class MessageMappingReflectiveProcessor implements ReflectiveProcessor {
this.bindingRegistrar.registerReflectionHints(hints, returnType.getGenericParameterType());
}
@Nullable
protected Type getMessageType(MethodParameter parameter) {
protected @Nullable Type getMessageType(MethodParameter parameter) {
MethodParameter nestedParameter = parameter.nested();
return (nestedParameter.getNestedParameterType() == nestedParameter.getParameterType() ?
null : nestedParameter.getNestedParameterType());

View File

@@ -1,9 +1,7 @@
/**
* Annotations and support classes for handling messages.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,6 +19,8 @@ package org.springframework.messaging.handler.annotation.reactive;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanExpressionContext;
import org.springframework.beans.factory.config.BeanExpressionResolver;
@@ -26,7 +28,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.ValueConstants;
import org.springframework.messaging.handler.invocation.reactive.SyncHandlerMethodArgumentResolver;
@@ -55,11 +56,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
private final ConversionService conversionService;
@Nullable
private final ConfigurableBeanFactory configurableBeanFactory;
private final @Nullable ConfigurableBeanFactory configurableBeanFactory;
@Nullable
private final BeanExpressionContext expressionContext;
private final @Nullable BeanExpressionContext expressionContext;
private final Map<MethodParameter, NamedValueInfo> namedValueInfoCache = new ConcurrentHashMap<>(256);
@@ -81,8 +80,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
@Override
@Nullable
public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
public @Nullable Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
MethodParameter nestedParameter = parameter.nestedIfOptional();
@@ -167,8 +165,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
* Resolve the given annotation-specified value,
* potentially containing placeholders and expressions.
*/
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) {
if (this.configurableBeanFactory == null || this.expressionContext == null) {
return value;
}
@@ -187,8 +184,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
* @param name the name of the value being resolved
* @return the resolved argument. May be {@code null}
*/
@Nullable
protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name);
protected abstract @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name);
/**
* Invoked when a value is required, but {@link #resolveArgumentInternal}
@@ -205,8 +201,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
* Specifically for booleans method parameters, use {@link Boolean#FALSE}.
* Also raise an ISE for primitive types.
*/
@Nullable
private Object handleNullValue(String name, @Nullable Object value, Class<?> paramType) {
private @Nullable Object handleNullValue(String name, @Nullable Object value, Class<?> paramType) {
if (value == null) {
if (paramType == boolean.class) {
return Boolean.FALSE;
@@ -231,8 +226,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
private final boolean required;
@Nullable
private final String defaultValue;
private final @Nullable String defaultValue;
protected NamedValueInfo(String name, boolean required, @Nullable String defaultValue) {
this.name = name;

View File

@@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.reactive;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.MessageHeaders;
@@ -59,9 +60,8 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu
}
@Override
@Nullable
@SuppressWarnings("unchecked")
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
MessageHeaders headers = message.getHeaders();
Map<String, String> vars = (Map<String, String>) headers.get(DESTINATION_TEMPLATE_VARIABLES_HEADER);
return vars != null ? vars.get(name) : null;

View File

@@ -21,11 +21,11 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.handler.annotation.Header;
@@ -67,8 +67,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
@Override
@Nullable
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
Object headerValue = message.getHeaders().get(name);
Object nativeHeaderValue = getNativeHeaderValue(message, name);
@@ -84,8 +83,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
return (headerValue != null ? headerValue : nativeHeaderValue);
}
@Nullable
private Object getNativeHeaderValue(Message<?> message, String name) {
private @Nullable Object getNativeHeaderValue(Message<?> message, String name) {
Map<String, List<String>> nativeHeaders = getNativeHeaders(message);
if (name.startsWith("nativeHeaders.")) {
name = name.substring("nativeHeaders.".length());
@@ -98,8 +96,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
@SuppressWarnings("unchecked")
@Nullable
private Map<String, List<String>> getNativeHeaders(Message<?> message) {
private @Nullable Map<String, List<String>> getNativeHeaders(Message<?> message) {
return (Map<String, List<String>>) message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
}

View File

@@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.reactive;
import java.lang.reflect.Method;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
@@ -49,8 +50,7 @@ public class HeadersMethodArgumentResolver implements SyncHandlerMethodArgumentR
}
@Override
@Nullable
public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
public @Nullable Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
Class<?> paramType = parameter.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return message.getHeaders();

View File

@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -39,7 +40,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.codec.Decoder;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.CompositeMessageCondition;
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
@@ -86,16 +86,13 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
private final List<Decoder<?>> decoders = new ArrayList<>();
@Nullable
private Validator validator;
private @Nullable Validator validator;
@Nullable
private RouteMatcher routeMatcher;
private @Nullable RouteMatcher routeMatcher;
private ConversionService conversionService = new DefaultFormattingConversionService();
@Nullable
private StringValueResolver valueResolver;
private @Nullable StringValueResolver valueResolver;
public MessageMappingMessageHandler() {
@@ -130,8 +127,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
/**
* Return the configured Validator instance.
*/
@Nullable
public Validator getValidator() {
public @Nullable Validator getValidator() {
return this.validator;
}
@@ -151,8 +147,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
* Return the {@code RouteMatcher} used to map messages to handlers.
* May be {@code null} before the component is initialized.
*/
@Nullable
public RouteMatcher getRouteMatcher() {
public @Nullable RouteMatcher getRouteMatcher() {
return this.routeMatcher;
}
@@ -272,8 +267,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
@Override
@Nullable
protected CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType) {
protected @Nullable CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType) {
CompositeMessageCondition methodCondition = getCondition(method);
if (methodCondition != null) {
CompositeMessageCondition typeCondition = getCondition(handlerType);
@@ -289,8 +283,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
* @param element the element to check
* @return the condition, or {@code null}
*/
@Nullable
protected CompositeMessageCondition getCondition(AnnotatedElement element) {
protected @Nullable CompositeMessageCondition getCondition(AnnotatedElement element) {
MessageMapping ann = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class);
if (ann == null || ann.value().length == 0) {
return null;
@@ -326,15 +319,13 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
}
@Override
@Nullable
protected RouteMatcher.Route getDestination(Message<?> message) {
protected RouteMatcher.@Nullable Route getDestination(Message<?> message) {
return (RouteMatcher.Route) message.getHeaders()
.get(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER);
}
@Override
@Nullable
protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message) {
protected @Nullable CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message) {
return mapping.getMatchingCondition(message);
}

View File

@@ -24,6 +24,7 @@ import java.util.function.Consumer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -37,7 +38,6 @@ import org.springframework.core.codec.Decoder;
import org.springframework.core.codec.DecodingException;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Payload;
@@ -79,8 +79,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
private final List<Decoder<?>> decoders;
@Nullable
private final Validator validator;
private final @Nullable Validator validator;
private final ReactiveAdapterRegistry adapterRegistry;
@@ -108,8 +107,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
/**
* Return the configured validator, if any.
*/
@Nullable
public Validator getValidator() {
public @Nullable Validator getValidator() {
return this.validator;
}
@@ -196,8 +194,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
* {@link MimeType} value or a String to parse to a {@link MimeType}.
* @param message the input message
*/
@Nullable
protected MimeType getMimeType(Message<?> message) {
protected @Nullable MimeType getMimeType(Message<?> message) {
Object headerValue = message.getHeaders().get(MessageHeaders.CONTENT_TYPE);
if (headerValue == null) {
return null;
@@ -279,8 +276,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
"Payload content is missing: " + param.getExecutable().toGenericString());
}
@Nullable
private Consumer<Object> getValidator(Message<?> message, MethodParameter parameter) {
private @Nullable Consumer<Object> getValidator(Message<?> message, MethodParameter parameter) {
if (this.validator == null) {
return null;
}

View File

@@ -2,9 +2,7 @@
* Support classes for working with annotated message-handling methods with
* non-blocking, reactive contracts.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler.annotation.reactive;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,6 +19,8 @@ package org.springframework.messaging.handler.annotation.support;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanExpressionContext;
import org.springframework.beans.factory.config.BeanExpressionResolver;
@@ -27,7 +29,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.ValueConstants;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
@@ -57,11 +58,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
private final ConversionService conversionService;
@Nullable
private final ConfigurableBeanFactory configurableBeanFactory;
private final @Nullable ConfigurableBeanFactory configurableBeanFactory;
@Nullable
private final BeanExpressionContext expressionContext;
private final @Nullable BeanExpressionContext expressionContext;
private final Map<MethodParameter, NamedValueInfo> namedValueInfoCache = new ConcurrentHashMap<>(256);
@@ -89,8 +88,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
public @Nullable Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
MethodParameter nestedParameter = parameter.nestedIfOptional();
@@ -177,8 +175,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* Resolve the given annotation-specified value,
* potentially containing placeholders and expressions.
*/
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) {
if (this.configurableBeanFactory == null || this.expressionContext == null) {
return value;
}
@@ -198,8 +195,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* @return the resolved argument. May be {@code null}
* @throws Exception in case of errors
*/
@Nullable
protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
protected abstract @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
throws Exception;
/**
@@ -217,8 +213,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* Specifically for booleans method parameters, use {@link Boolean#FALSE}.
* Also raise an ISE for primitive types.
*/
@Nullable
private Object handleNullValue(String name, @Nullable Object value, Class<?> paramType) {
private @Nullable Object handleNullValue(String name, @Nullable Object value, Class<?> paramType) {
if (value == null) {
if (paramType == boolean.class) {
return Boolean.FALSE;
@@ -254,8 +249,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
private final boolean required;
@Nullable
private final String defaultValue;
private final @Nullable String defaultValue;
protected NamedValueInfo(String name, boolean required, @Nullable String defaultValue) {
this.name = name;

View File

@@ -20,13 +20,14 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.converter.GenericMessageConverter;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
@@ -62,20 +63,16 @@ public class DefaultMessageHandlerMethodFactory
private ConversionService conversionService = new DefaultFormattingConversionService();
@Nullable
private MessageConverter messageConverter;
private @Nullable MessageConverter messageConverter;
@Nullable
private Validator validator;
private @Nullable Validator validator;
@Nullable
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
private @Nullable List<HandlerMethodArgumentResolver> customArgumentResolvers;
private final HandlerMethodArgumentResolverComposite argumentResolvers =
new HandlerMethodArgumentResolverComposite();
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
/**

View File

@@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.support;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.MessageHeaders;
@@ -59,9 +60,8 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu
}
@Override
@Nullable
@SuppressWarnings("unchecked")
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) {
MessageHeaders headers = message.getHeaders();
Map<String, String> vars = (Map<String, String>) headers.get(DESTINATION_TEMPLATE_VARIABLES_HEADER);
return vars != null ? vars.get(name) : null;

View File

@@ -21,11 +21,11 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.handler.annotation.Header;
@@ -68,8 +68,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
@Override
@Nullable
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
throws Exception {
Object headerValue = message.getHeaders().get(name);
@@ -86,8 +85,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
return (headerValue != null ? headerValue : nativeHeaderValue);
}
@Nullable
private Object getNativeHeaderValue(Message<?> message, String name) {
private @Nullable Object getNativeHeaderValue(Message<?> message, String name) {
Map<String, List<String>> nativeHeaders = getNativeHeaders(message);
if (name.startsWith("nativeHeaders.")) {
name = name.substring("nativeHeaders.".length());
@@ -100,8 +98,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
@SuppressWarnings("unchecked")
@Nullable
private Map<String, List<String>> getNativeHeaders(Message<?> message) {
private @Nullable Map<String, List<String>> getNativeHeaders(Message<?> message) {
return (Map<String, List<String>>) message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
}

View File

@@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.support;
import java.lang.reflect.Method;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
@@ -49,8 +50,7 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol
}
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
public @Nullable Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Class<?> paramType = parameter.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return message.getHeaders();

View File

@@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.support;
import java.lang.reflect.Type;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
@@ -43,8 +44,7 @@ import org.springframework.util.StringUtils;
*/
public class MessageMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Nullable
private final MessageConverter converter;
private final @Nullable MessageConverter converter;
/**

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler.annotation.support;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.invocation.MethodArgumentResolutionException;
import org.springframework.validation.BindingResult;
@@ -34,8 +35,7 @@ import org.springframework.validation.ObjectError;
@SuppressWarnings("serial")
public class MethodArgumentNotValidException extends MethodArgumentResolutionException {
@Nullable
private final BindingResult bindingResult;
private final @Nullable BindingResult bindingResult;
/**
@@ -60,8 +60,7 @@ public class MethodArgumentNotValidException extends MethodArgumentResolutionExc
* Return the BindingResult if the failure is validation-related,
* or {@code null} if none.
*/
@Nullable
public final BindingResult getBindingResult() {
public final @Nullable BindingResult getBindingResult() {
return this.bindingResult;
}

View File

@@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.support;
import java.lang.annotation.Annotation;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
@@ -61,8 +62,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
private final MessageConverter converter;
@Nullable
private final Validator validator;
private final @Nullable Validator validator;
private final boolean useDefaultResolution;
@@ -111,8 +111,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
}
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
public @Nullable Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Payload ann = parameter.getParameterAnnotation(Payload.class);
if (ann != null && StringUtils.hasText(ann.expression())) {
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");

View File

@@ -1,9 +1,7 @@
/**
* Support classes for working with annotated message-handling methods.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler.annotation.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler.invocation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**

View File

@@ -22,8 +22,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ExceptionDepthComparator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
@@ -98,8 +99,7 @@ public abstract class AbstractExceptionHandlerMethodResolver {
* @param exception the exception
* @return a Method to handle the exception, or {@code null} if none found
*/
@Nullable
public Method resolveMethod(Throwable exception) {
public @Nullable Method resolveMethod(Throwable exception) {
Method method = resolveMethodByExceptionType(exception.getClass());
if (method == null) {
Throwable cause = exception.getCause();
@@ -118,8 +118,7 @@ public abstract class AbstractExceptionHandlerMethodResolver {
* @return a Method to handle the exception, or {@code null} if none found
* @since 4.3.1
*/
@Nullable
public Method resolveMethodByExceptionType(Class<? extends Throwable> exceptionType) {
public @Nullable Method resolveMethodByExceptionType(Class<? extends Throwable> exceptionType) {
Method method = this.exceptionLookupCache.get(exceptionType);
if (method == null) {
method = getMappedMethod(exceptionType);
@@ -132,8 +131,7 @@ public abstract class AbstractExceptionHandlerMethodResolver {
* Return the {@link Method} mapped to the given exception type, or
* {@link #NO_MATCHING_EXCEPTION_HANDLER_METHOD} if none.
*/
@Nullable
private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
private @Nullable Method getMappedMethod(Class<? extends Throwable> exceptionType) {
List<Class<? extends Throwable>> matches = new ArrayList<>();
for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
if (mappedException.isAssignableFrom(exceptionType)) {

View File

@@ -34,13 +34,13 @@ import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHandlingException;
@@ -89,8 +89,7 @@ public abstract class AbstractMethodMessageHandler<T>
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private Log handlerMethodLogger;
private @Nullable Log handlerMethodLogger;
private final List<String> destinationPrefixes = new ArrayList<>();
@@ -105,8 +104,7 @@ public abstract class AbstractMethodMessageHandler<T>
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =
new HandlerMethodReturnValueHandlerComposite();
@Nullable
private ApplicationContext applicationContext;
private @Nullable ApplicationContext applicationContext;
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<>(64);
@@ -225,8 +223,7 @@ public abstract class AbstractMethodMessageHandler<T>
this.applicationContext = applicationContext;
}
@Nullable
public ApplicationContext getApplicationContext() {
public @Nullable ApplicationContext getApplicationContext() {
return this.applicationContext;
}
@@ -343,8 +340,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @param handlerType the handler type, possibly a subtype of the method's declaring class
* @return the mapping, or {@code null} if the method is not mapped
*/
@Nullable
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
protected abstract @Nullable T getMappingForMethod(Method method, Class<?> handlerType);
/**
* Register a handler method and its unique mapping.
@@ -399,8 +395,7 @@ public abstract class AbstractMethodMessageHandler<T>
* Return a logger to set on {@link HandlerMethodReturnValueHandlerComposite}.
* @since 5.1
*/
@Nullable
protected Log getReturnValueHandlerLogger() {
protected @Nullable Log getReturnValueHandlerLogger() {
return null;
}
@@ -408,8 +403,7 @@ public abstract class AbstractMethodMessageHandler<T>
* Return a logger to set on {@link InvocableHandlerMethod}.
* @since 5.1
*/
@Nullable
protected Log getHandlerMethodLogger() {
protected @Nullable Log getHandlerMethodLogger() {
return null;
}
@@ -458,8 +452,7 @@ public abstract class AbstractMethodMessageHandler<T>
headerAccessor.setImmutable();
}
@Nullable
protected abstract String getDestination(Message<?> message);
protected abstract @Nullable String getDestination(Message<?> message);
/**
* Check whether the given destination (of an incoming message) matches to
@@ -469,8 +462,7 @@ public abstract class AbstractMethodMessageHandler<T>
* <p>If there are no destination prefixes, return the destination as is.
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
@Nullable
protected String getLookupDestination(@Nullable String destination) {
protected @Nullable String getLookupDestination(@Nullable String destination) {
if (destination == null) {
return null;
}
@@ -539,8 +531,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @param message the message being handled
* @return the match or {@code null} if there is no match
*/
@Nullable
protected abstract T getMatchingMapping(T mapping, Message<?> message);
protected abstract @Nullable T getMatchingMapping(T mapping, Message<?> message);
protected void handleNoMatch(Set<T> ts, String lookupDestination, Message<?> message) {
logger.debug("No matching message handler methods.");
@@ -628,8 +619,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @return a method to handle the exception, or {@code null}
* @since 4.2
*/
@Nullable
protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
protected @Nullable InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
if (logger.isDebugEnabled()) {
logger.debug("Searching methods to handle " + exception.getClass().getSimpleName());
}

View File

@@ -18,8 +18,9 @@ package org.springframework.messaging.handler.invocation;
import java.util.concurrent.CompletableFuture;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
/**
* An extension of {@link HandlerMethodReturnValueHandler} for handling async,
@@ -61,7 +62,6 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
* no further handling will be performed
* @since 6.0
*/
@Nullable
CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType);
@Nullable CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType);
}

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler.invocation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -48,7 +49,6 @@ public interface HandlerMethodArgumentResolver {
* @return the resolved argument value, or {@code null}
* @throws Exception in case of errors with the preparation of argument values
*/
@Nullable
Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception;
@Nullable Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception;
}

View File

@@ -22,8 +22,9 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -108,8 +109,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
* @throws IllegalArgumentException if no suitable argument resolver is found
*/
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
public @Nullable Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
if (resolver == null) {
throw new IllegalArgumentException("Unsupported parameter type [" +
@@ -122,8 +122,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
* Find a registered {@link HandlerMethodArgumentResolver} that supports
* the given method parameter.
*/
@Nullable
private HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {
private @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {
HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter);
if (result == null) {
for (HandlerMethodArgumentResolver resolver : this.argumentResolvers) {

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler.invocation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**

View File

@@ -23,9 +23,9 @@ import java.util.concurrent.CompletableFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -102,8 +102,7 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
}
@SuppressWarnings("ForLoopReplaceableByForEach")
@Nullable
private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) {
private @Nullable HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) {
for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) {
if (handler.supportsReturnType(returnType)) {
return handler;
@@ -134,8 +133,7 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
}
@Override
@Nullable
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
public @Nullable CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler) {
return asyncHandler.toCompletableFuture(returnValue, returnType);

View File

@@ -21,11 +21,12 @@ import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;
import org.jspecify.annotations.Nullable;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.HandlerMethod;
import org.springframework.util.ObjectUtils;
@@ -110,9 +111,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
* @see #getMethodArgumentValues
* @see #doInvoke
*/
@Nullable
public Object invoke(Message<?> message, @Nullable Object... providedArgs) throws Exception {
Object[] args = getMethodArgumentValues(message, providedArgs);
public @Nullable Object invoke(Message<?> message, @Nullable Object... providedArgs) throws Exception {
@Nullable Object[] args = getMethodArgumentValues(message, providedArgs);
if (logger.isTraceEnabled()) {
logger.trace("Arguments: " + Arrays.toString(args));
}
@@ -125,13 +125,13 @@ public class InvocableHandlerMethod extends HandlerMethod {
* <p>The resulting array will be passed into {@link #doInvoke}.
* @since 5.1.2
*/
protected Object[] getMethodArgumentValues(Message<?> message, @Nullable Object... providedArgs) throws Exception {
protected @Nullable Object[] getMethodArgumentValues(Message<?> message, @Nullable Object... providedArgs) throws Exception {
MethodParameter[] parameters = getMethodParameters();
if (ObjectUtils.isEmpty(parameters)) {
return EMPTY_ARGS;
}
Object[] args = new Object[parameters.length];
@Nullable Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
@@ -163,8 +163,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
/**
* Invoke the handler method with the given argument values.
*/
@Nullable
protected Object doInvoke(Object... args) throws Exception {
protected @Nullable Object doInvoke(@Nullable Object... args) throws Exception {
try {
return getBridgedMethod().invoke(getBean(), args);
}
@@ -199,8 +198,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
private class AsyncResultMethodParameter extends AnnotatedMethodParameter {
@Nullable
private final Object returnValue;
private final @Nullable Object returnValue;
private final ResolvableType returnType;

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.handler.invocation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;

View File

@@ -18,12 +18,12 @@ package org.springframework.messaging.handler.invocation;
import java.util.concurrent.CompletableFuture;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.lang.Nullable;
/**
* Support for single-value reactive types (like {@code Mono} or {@code Single})
@@ -58,8 +58,7 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler
}
@Override
@Nullable
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
public @Nullable CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
if (adapter != null) {
return Mono.from(adapter.toPublisher(returnValue)).toFuture();

View File

@@ -1,9 +1,7 @@
/**
* Common infrastructure for invoking message handler methods.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler.invocation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -36,7 +37,6 @@ import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
@@ -166,9 +166,8 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
}
}
@Nullable
@SuppressWarnings("unchecked")
private <T> Encoder<T> getEncoder(ResolvableType elementType, @Nullable MimeType mimeType) {
private <T> @Nullable Encoder<T> getEncoder(ResolvableType elementType, @Nullable MimeType mimeType) {
for (Encoder<?> encoder : getEncoders()) {
if (encoder.canEncode(elementType, mimeType)) {
return (Encoder<T>) encoder;

View File

@@ -33,6 +33,7 @@ import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.BeanNameAware;
@@ -41,7 +42,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.ReactiveMessageHandler;
@@ -87,11 +87,9 @@ public abstract class AbstractMethodMessageHandler<T>
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private Predicate<Class<?>> handlerPredicate;
private @Nullable Predicate<Class<?>> handlerPredicate;
@Nullable
List<Object> handlers;
@Nullable List<Object> handlers;
private ArgumentResolverConfigurer argumentResolverConfigurer = new ArgumentResolverConfigurer();
@@ -99,11 +97,9 @@ public abstract class AbstractMethodMessageHandler<T>
private final InvocableHelper invocableHelper = new InvocableHelper(this::createExceptionMethodResolverFor);
@Nullable
private ApplicationContext applicationContext;
private @Nullable ApplicationContext applicationContext;
@Nullable
private String beanName;
private @Nullable String beanName;
private final Map<T, HandlerMethod> handlerMethods = new ConcurrentHashMap<>(64);
@@ -124,8 +120,7 @@ public abstract class AbstractMethodMessageHandler<T>
/**
* Return the {@link #setHandlerPredicate configured} handler predicate.
*/
@Nullable
public Predicate<Class<?>> getHandlerPredicate() {
public @Nullable Predicate<Class<?>> getHandlerPredicate() {
return this.handlerPredicate;
}
@@ -193,8 +188,7 @@ public abstract class AbstractMethodMessageHandler<T>
this.applicationContext = applicationContext;
}
@Nullable
public ApplicationContext getApplicationContext() {
public @Nullable ApplicationContext getApplicationContext() {
return this.applicationContext;
}
@@ -365,8 +359,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @param handlerType the handler type, possibly a subtype of the method's declaring class
* @return the mapping, or {@code null} if the method is not mapped
*/
@Nullable
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
protected abstract @Nullable T getMappingForMethod(Method method, Class<?> handlerType);
/**
* Register a handler method and its unique mapping.
@@ -461,8 +454,7 @@ public abstract class AbstractMethodMessageHandler<T>
return this.invocableHelper.handleMessage(handlerMethod, message);
}
@Nullable
private Match<T> getHandlerMethod(Message<?> message) {
private @Nullable Match<T> getHandlerMethod(Message<?> message) {
List<Match<T>> matches = new ArrayList<>();
RouteMatcher.Route destination = getDestination(message);
@@ -502,8 +494,7 @@ public abstract class AbstractMethodMessageHandler<T>
* Extract the destination from the given message.
* @see #getDirectLookupMappings(Object)
*/
@Nullable
protected abstract RouteMatcher.Route getDestination(Message<?> message);
protected abstract RouteMatcher.@Nullable Route getDestination(Message<?> message);
@SuppressWarnings("NullAway")
private void addMatchesToCollection(
@@ -524,8 +515,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @param message the message being handled
* @return the match or {@code null} if there is no match
*/
@Nullable
protected abstract T getMatchingMapping(T mapping, Message<?> message);
protected abstract @Nullable T getMatchingMapping(T mapping, Message<?> message);
/**
* Return a comparator for sorting matching mappings.
@@ -540,7 +530,7 @@ public abstract class AbstractMethodMessageHandler<T>
* @param destination the destination
* @param message the message
*/
protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message) {
protected void handleNoMatch(RouteMatcher.@Nullable Route destination, Message<?> message) {
logger.debug("No handlers for destination '" +
(destination != null ? destination.value() : "") + "'");
}

View File

@@ -18,6 +18,7 @@ package org.springframework.messaging.handler.invocation.reactive;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
@@ -30,7 +31,6 @@ import reactor.util.context.Context;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -68,9 +68,8 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
@Override
@Nullable
@SuppressWarnings("rawtypes")
public Object scanUnsafe(Attr key) {
public @Nullable Object scanUnsafe(Attr key) {
if (key == Attr.PREFETCH) {
return Integer.MAX_VALUE;
}
@@ -134,16 +133,13 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
private final WriteCompletionBarrier writeCompletionBarrier;
/* Upstream write source subscription */
@Nullable
private Subscription subscription;
private @Nullable Subscription subscription;
/** Cached data item before readyToWrite. */
@Nullable
private T item;
private @Nullable T item;
/** Cached error signal before readyToWrite. */
@Nullable
private Throwable error;
private @Nullable Throwable error;
/** Cached onComplete signal before readyToWrite. */
private boolean completed = false;
@@ -155,8 +151,7 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
private State state = State.NEW;
/** The actual writeSubscriber from the HTTP server adapter. */
@Nullable
private Subscriber<? super T> writeSubscriber;
private @Nullable Subscriber<? super T> writeSubscriber;
WriteBarrier(CoreSubscriber<? super Void> completionSubscriber) {
@@ -391,8 +386,7 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
private final WriteBarrier writeBarrier;
@Nullable
private Subscription subscription;
private @Nullable Subscription subscription;
public WriteCompletionBarrier(CoreSubscriber<? super Void> subscriber, WriteBarrier writeBarrier) {

View File

@@ -24,10 +24,10 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -124,8 +124,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
* Find a registered {@link HandlerMethodArgumentResolver} that supports
* the given method parameter.
*/
@Nullable
public HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {
public @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {
HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter);
if (result == null) {
for (HandlerMethodArgumentResolver methodArgumentResolver : this.argumentResolvers) {

View File

@@ -16,10 +16,10 @@
package org.springframework.messaging.handler.invocation.reactive;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**

View File

@@ -22,10 +22,10 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -93,8 +93,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
}
@SuppressWarnings("ForLoopReplaceableByForEach")
@Nullable
private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) {
private @Nullable HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) {
for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) {
if (handler.supportsReturnType(returnType)) {
return handler;

View File

@@ -25,11 +25,11 @@ import java.util.function.Function;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.HandlerMethod;
import org.springframework.messaging.handler.MessagingAdviceBean;
@@ -146,8 +146,7 @@ class InvocableHelper {
* @param ex the exception raised or signaled
* @return a method to handle the exception, or {@code null}
*/
@Nullable
public InvocableHandlerMethod initExceptionHandlerMethod(HandlerMethod handlerMethod, Throwable ex) {
public @Nullable InvocableHandlerMethod initExceptionHandlerMethod(HandlerMethod handlerMethod, Throwable ex) {
if (logger.isDebugEnabled()) {
logger.debug("Searching for methods to handle " + ex.getClass().getSimpleName());
}

View File

@@ -16,10 +16,10 @@
package org.springframework.messaging.handler.invocation.reactive;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -47,7 +47,6 @@ public interface SyncHandlerMethodArgumentResolver extends HandlerMethodArgument
* @param message the currently processed message
* @return the resolved value, if any
*/
@Nullable
Object resolveArgumentValue(MethodParameter parameter, Message<?> message);
@Nullable Object resolveArgumentValue(MethodParameter parameter, Message<?> message);
}

View File

@@ -2,9 +2,7 @@
* Common infrastructure for invoking message handler methods with non-blocking,
* and reactive contracts.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler.invocation.reactive;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Basic abstractions for working with message handler methods.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.handler;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Support for working with messaging APIs and protocols.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -32,13 +32,13 @@ import io.rsocket.metadata.RoutingMetadata;
import io.rsocket.metadata.WellKnownMimeType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
import org.springframework.core.codec.Decoder;
import org.springframework.core.io.buffer.NettyDataBuffer;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
/**

View File

@@ -23,6 +23,7 @@ import java.util.function.Consumer;
import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.core.RSocketClient;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -35,7 +36,6 @@ import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
@@ -52,8 +52,7 @@ final class DefaultRSocketRequester implements RSocketRequester {
private final RSocketClient rsocketClient;
@Nullable
private final RSocket rsocket;
private final @Nullable RSocket rsocket;
private final MimeType dataMimeType;
@@ -87,9 +86,8 @@ final class DefaultRSocketRequester implements RSocketRequester {
return this.rsocketClient;
}
@Nullable
@Override
public RSocket rsocket() {
public @Nullable RSocket rsocket() {
return this.rsocket;
}
@@ -132,11 +130,9 @@ final class DefaultRSocketRequester implements RSocketRequester {
private final MetadataEncoder metadataEncoder = new MetadataEncoder(metadataMimeType(), strategies);
@Nullable
private Mono<Payload> payloadMono;
private @Nullable Mono<Payload> payloadMono;
@Nullable
private Flux<Payload> payloadFlux;
private @Nullable Flux<Payload> payloadFlux;
public DefaultRequestSpec(String route, Object... vars) {
@@ -178,8 +174,7 @@ final class DefaultRSocketRequester implements RSocketRequester {
return this;
}
@Nullable
private ReactiveAdapter getAdapter(Class<?> aClass) {
private @Nullable ReactiveAdapter getAdapter(Class<?> aClass) {
return strategies.reactiveAdapterRegistry().getAdapter(aClass);
}

View File

@@ -36,6 +36,7 @@ import io.rsocket.transport.ClientTransport;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.client.WebsocketClientTransport;
import io.rsocket.util.DefaultPayload;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@@ -47,7 +48,6 @@ import org.springframework.core.codec.StringDecoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeType;
@@ -69,26 +69,19 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
private static final Payload EMPTY_SETUP_PAYLOAD = DefaultPayload.create(EMPTY_BYTE_ARRAY);
@Nullable
private MimeType dataMimeType;
private @Nullable MimeType dataMimeType;
@Nullable
private MimeType metadataMimeType;
private @Nullable MimeType metadataMimeType;
@Nullable
private Object setupData;
private @Nullable Object setupData;
@Nullable
private String setupRoute;
private @Nullable String setupRoute;
@Nullable
private Object[] setupRouteVars;
private Object @Nullable [] setupRouteVars;
@Nullable
private Map<Object, MimeType> setupMetadata;
private @Nullable Map<Object, MimeType> setupMetadata;
@Nullable
private RSocketStrategies strategies;
private @Nullable RSocketStrategies strategies;
private final List<Consumer<RSocketStrategies.Builder>> strategiesConfigurers = new ArrayList<>();

View File

@@ -23,6 +23,7 @@ import java.util.List;
import java.util.function.Consumer;
import io.netty.buffer.PooledByteBufAllocator;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.codec.ByteArrayDecoder;
@@ -37,7 +38,6 @@ import org.springframework.core.codec.Encoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.RouteMatcher;
import org.springframework.util.SimpleRouteMatcher;
@@ -117,17 +117,13 @@ final class DefaultRSocketStrategies implements RSocketStrategies {
private final List<Decoder<?>> decoders = new ArrayList<>();
@Nullable
private RouteMatcher routeMatcher;
private @Nullable RouteMatcher routeMatcher;
@Nullable
private ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
private @Nullable ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
@Nullable
private DataBufferFactory bufferFactory;
private @Nullable DataBufferFactory bufferFactory;
@Nullable
private MetadataExtractor metadataExtractor;
private @Nullable MetadataExtractor metadataExtractor;
private final List<Consumer<MetadataExtractorRegistry>> metadataExtractors = new ArrayList<>();

View File

@@ -27,6 +27,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;
import io.rsocket.metadata.WellKnownMimeType;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.core.ReactiveAdapter;
@@ -35,7 +36,6 @@ import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeType;
@@ -63,8 +63,7 @@ final class MetadataEncoder {
private final ByteBufAllocator allocator;
@Nullable
private String route;
private @Nullable String route;
private final List<MetadataEntry> metadataEntries = new ArrayList<>(4);
@@ -155,7 +154,7 @@ final class MetadataEncoder {
* Add route and/or metadata, both optional.
*/
public MetadataEncoder metadataAndOrRoute(@Nullable Map<Object, MimeType> metadata,
@Nullable String route, @Nullable Object[] vars) {
@Nullable String route, Object @Nullable [] vars) {
if (route != null) {
this.route = expand(route, vars != null ? vars : new Object[0]);

View File

@@ -19,8 +19,9 @@ package org.springframework.messaging.rsocket;
import java.util.Map;
import java.util.function.BiConsumer;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
/**

View File

@@ -29,6 +29,7 @@ import io.rsocket.loadbalance.LoadbalanceTarget;
import io.rsocket.transport.ClientTransport;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.client.WebsocketClientTransport;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
@@ -37,7 +38,6 @@ import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.codec.Decoder;
import org.springframework.lang.Nullable;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.MimeType;
@@ -64,8 +64,7 @@ public interface RSocketRequester extends Disposable {
* or via one of the (deprecated) connect methods on the
* {@code RSocketRequester} builder, or otherwise return {@code null}.
*/
@Nullable
RSocket rsocket();
@Nullable RSocket rsocket();
/**
* Return the data {@code MimeType} selected for the underlying RSocket

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.function.Consumer;
import io.rsocket.Payload;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.ResolvableType;
@@ -28,7 +29,6 @@ import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.MimeType;
import org.springframework.util.RouteMatcher;

View File

@@ -1,9 +1,7 @@
/**
* Annotations and support classes for handling RSocket streams.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.rsocket.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -24,6 +24,7 @@ import io.rsocket.ConnectionSetupPayload;
import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.frame.FrameType;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -31,7 +32,6 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.NettyDataBuffer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.ReactiveMessageHandler;

View File

@@ -24,8 +24,8 @@ import java.util.Map;
import java.util.Set;
import io.rsocket.frame.FrameType;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.AbstractMessageCondition;
import org.springframework.util.Assert;
@@ -117,8 +117,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
* @param message the current message
* @return the frame type or {@code null} if not found
*/
@Nullable
public static FrameType getFrameType(Message<?> message) {
public static @Nullable FrameType getFrameType(Message<?> message) {
return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER);
}
@@ -134,8 +133,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
}
@Override
@Nullable
public RSocketFrameTypeMessageCondition getMatchingCondition(Message<?> message) {
public @Nullable RSocketFrameTypeMessageCondition getMatchingCondition(Message<?> message) {
FrameType actual = message.getHeaders().get(FRAME_TYPE_HEADER, FrameType.class);
if (actual != null) {
for (FrameType type : this.frameTypes) {

View File

@@ -28,6 +28,7 @@ import io.rsocket.RSocket;
import io.rsocket.SocketAcceptor;
import io.rsocket.frame.FrameType;
import io.rsocket.metadata.WellKnownMimeType;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.beans.BeanUtils;
@@ -38,7 +39,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.codec.Decoder;
import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.PooledDataBuffer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.handler.CompositeMessageCondition;
@@ -96,8 +96,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
private RSocketStrategies strategies = RSocketStrategies.create();
@Nullable
private MimeType defaultDataMimeType;
private @Nullable MimeType defaultDataMimeType;
private MimeType defaultMetadataMimeType = MimeTypeUtils.parseMimeType(
WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
@@ -256,8 +255,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
* Return the configured
* {@link #setDefaultDataMimeType defaultDataMimeType}, or {@code null}.
*/
@Nullable
public MimeType getDefaultDataMimeType() {
public @Nullable MimeType getDefaultDataMimeType() {
return this.defaultDataMimeType;
}
@@ -311,8 +309,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
@Override
@Nullable
protected CompositeMessageCondition getCondition(AnnotatedElement element) {
protected @Nullable CompositeMessageCondition getCondition(AnnotatedElement element) {
MessageMapping ann1 = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class);
if (ann1 != null && ann1.value().length > 0) {
return new CompositeMessageCondition(
@@ -379,7 +376,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
}
@Override
protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message) {
protected void handleNoMatch(RouteMatcher.@Nullable Route destination, Message<?> message) {
FrameType frameType = RSocketFrameTypeMessageCondition.getFrameType(message);
if (frameType == FrameType.SETUP || frameType == FrameType.METADATA_PUSH) {
if (frameType == FrameType.SETUP && message.getPayload() instanceof PooledDataBuffer pooledDataBuffer) {

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import io.rsocket.Payload;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -27,7 +28,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.invocation.reactive.AbstractEncoderMethodReturnValueHandler;
import org.springframework.messaging.rsocket.PayloadUtils;
@@ -75,9 +75,8 @@ public class RSocketPayloadReturnValueHandler extends AbstractEncoderMethodRetur
return Mono.empty();
}
@Nullable
@SuppressWarnings("unchecked")
private AtomicReference<Flux<Payload>> getResponseReference(Message<?> message) {
private @Nullable AtomicReference<Flux<Payload>> getResponseReference(Message<?> message) {
Object headerValue = message.getHeaders().get(RESPONSE_HEADER);
Assert.state(headerValue == null || headerValue instanceof AtomicReference, "Expected AtomicReference");
return (AtomicReference<Flux<Payload>>) headerValue;

View File

@@ -1,9 +1,7 @@
/**
* Support classes for working with annotated RSocket stream handling methods.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.rsocket.annotation.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Support for the RSocket protocol.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.messaging.rsocket;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,8 +18,9 @@ package org.springframework.messaging.rsocket.service;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.handler.annotation.DestinationVariable;
/**

View File

@@ -16,8 +16,9 @@
package org.springframework.messaging.rsocket.service;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;

Some files were not shown because too many files have changed in this diff Show More