From c472a3814bfe5c8397f4270e5ffdc51b22bc42c9 Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Sat, 23 Aug 2025 17:57:33 +0700 Subject: [PATCH 1/2] GH-10083: Apply Nullability to core `history` and `filter` packages Related to: #10083 Signed-off-by: Tran Ngoc Nhan --- .../integration/filter/MessageFilter.java | 10 ++++++---- .../integration/filter/package-info.java | 1 + .../history/HistoryWritingMessagePostProcessor.java | 4 +++- .../integration/history/MessageHistoryConfigurer.java | 1 + .../integration/history/package-info.java | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java index b6bcef2312a..dddd6d02933 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -16,6 +16,8 @@ package org.springframework.integration.filter; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.context.Lifecycle; @@ -53,9 +55,9 @@ public class MessageFilter extends AbstractReplyProducingPostProcessingMessageHa private boolean throwExceptionOnRejection; - private MessageChannel discardChannel; + private @Nullable MessageChannel discardChannel; - private String discardChannelName; + private @Nullable String discardChannelName; /** * Create a MessageFilter that will delegate to the given {@link MessageSelector}. @@ -111,7 +113,7 @@ public void setDiscardWithinAdvice(boolean discardWithinAdvice) { } @Override - public MessageChannel getDiscardChannel() { + public @Nullable MessageChannel getDiscardChannel() { String channelName = this.discardChannelName; if (channelName != null) { this.discardChannel = getChannelResolver().resolveDestination(channelName); @@ -166,7 +168,7 @@ public boolean isRunning() { } @Override - protected Object doHandleRequestMessage(Message message) { + protected @Nullable Object doHandleRequestMessage(Message message) { if (this.selector.accept(message)) { return message; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/package-info.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/package-info.java index 2b1d4190e67..16f44b4707d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/package-info.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes supporting the filter pattern. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.filter; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/HistoryWritingMessagePostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/history/HistoryWritingMessagePostProcessor.java index 38d28b47c85..6ea980605c3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/HistoryWritingMessagePostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/HistoryWritingMessagePostProcessor.java @@ -16,6 +16,8 @@ package org.springframework.integration.history; +import org.jspecify.annotations.Nullable; + import org.springframework.integration.support.DefaultMessageBuilderFactory; import org.springframework.integration.support.MessageBuilderFactory; import org.springframework.integration.support.management.TrackableComponent; @@ -29,7 +31,7 @@ */ public class HistoryWritingMessagePostProcessor implements MessagePostProcessor { - private volatile TrackableComponent trackableComponent; + private volatile @Nullable TrackableComponent trackableComponent; private volatile boolean shouldTrack; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java index 9bd9ab8eec8..25e10276676 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java @@ -63,6 +63,7 @@ public class MessageHistoryConfigurer implements ManageableSmartLifecycle, BeanF private String[] componentNamePatterns = {"*"}; + @SuppressWarnings("NullAway.Init") private ListableBeanFactory beanFactory; private boolean autoStartup = true; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/package-info.java b/spring-integration-core/src/main/java/org/springframework/integration/history/package-info.java index bb452b4b98b..66452fd5155 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/package-info.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/package-info.java @@ -1,4 +1,5 @@ /** * Provides classes supporting the capture of message history. */ +@org.jspecify.annotations.NullMarked package org.springframework.integration.history; From d626a5ac7b74f0cac23db681b9da1d5915be3f6e Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Sat, 23 Aug 2025 18:35:10 +0700 Subject: [PATCH 2/2] Remove explicit type and redundant condition Signed-off-by: Tran Ngoc Nhan --- .../integration/filter/MessageFilter.java | 10 ++++------ .../integration/filter/MethodInvokingSelector.java | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java index dddd6d02933..33b9fb9fad8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -136,15 +136,13 @@ public IntegrationPatternType getIntegrationPatternType() { protected void doInit() { Assert.state(!(this.discardChannelName != null && this.discardChannel != null), "'discardChannelName' and 'discardChannel' are mutually exclusive."); - if (this.selector instanceof AbstractMessageProcessingSelector) { + if (this.selector instanceof AbstractMessageProcessingSelector abstractMessageProcessingSelector) { ConversionService conversionService = getConversionService(); - if (conversionService != null) { - ((AbstractMessageProcessingSelector) this.selector).setConversionService(conversionService); - } + abstractMessageProcessingSelector.setConversionService(conversionService); } BeanFactory beanFactory = getBeanFactory(); - if (this.selector instanceof BeanFactoryAware && beanFactory != null) { - ((BeanFactoryAware) this.selector).setBeanFactory(beanFactory); + if (this.selector instanceof BeanFactoryAware beanFactoryAware) { + beanFactoryAware.setBeanFactory(beanFactory); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java index 17a90735bc5..945dac463a5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java @@ -34,7 +34,7 @@ public class MethodInvokingSelector extends AbstractMessageProcessingSelector { public MethodInvokingSelector(Object object, Method method) { - super(new MethodInvokingMessageProcessor(object, method)); + super(new MethodInvokingMessageProcessor<>(object, method)); Class returnType = method.getReturnType(); Assert.isTrue(boolean.class.isAssignableFrom(returnType) || Boolean.class.isAssignableFrom(returnType), @@ -42,13 +42,13 @@ public MethodInvokingSelector(Object object, Method method) { } public MethodInvokingSelector(Object object, String methodName) { - super(new MethodInvokingMessageProcessor(object, methodName)); + super(new MethodInvokingMessageProcessor<>(object, methodName)); } @SuppressWarnings("unchecked") public MethodInvokingSelector(Object object) { super(object instanceof MessageProcessor ? (MessageProcessor) object : - new MethodInvokingMessageProcessor(object, Filter.class)); + new MethodInvokingMessageProcessor<>(object, Filter.class)); } }