Skip to content

Commit 9f3575e

Browse files
authored
GH-10083: Add NullaWay to package-info for o.s.i.config package
Related to: #10083 Add `@org.jspecify.annotations.NullAway` to the `package-info.java` Apply `@Nullable`, `@SuppressWarnings("NullAway.Init)` as need. Tweak code as necessary in locations where NullAway can not discern that the null condition is already mitigated * Remove `Objects.requireNonNull` surround `this.handler` in the `AbstractSimpleMessageHandlerFactoryBean` Remove commented code in `AbstractSimpleMessageHandlerFactoryBean.extractTarget` Restructure `IntegrationManagementConfigurer.registerComponentGauges` so that a NullAway suppression can be removed from the method
1 parent 5f576b3 commit 9f3575e

38 files changed

+245
-120
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class AggregatingMessageHandler extends AbstractCorrelatingMessageHandler
4343
private volatile boolean expireGroupsUponCompletion = false;
4444

4545
public AggregatingMessageHandler(MessageGroupProcessor processor, MessageGroupStore store,
46-
CorrelationStrategy correlationStrategy, ReleaseStrategy releaseStrategy) {
46+
@Nullable CorrelationStrategy correlationStrategy, @Nullable ReleaseStrategy releaseStrategy) {
4747

4848
super(processor, store, correlationStrategy, releaseStrategy);
4949
}

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractEvaluationContextFactoryBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public abstract class AbstractEvaluationContextFactoryBean implements Applicatio
5656

5757
private TypeConverter typeConverter = new StandardTypeConverter();
5858

59+
@SuppressWarnings("NullAway.Init")
5960
private ApplicationContext applicationContext;
6061

6162
@Nullable

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collection;
2424
import java.util.Collections;
2525
import java.util.List;
26+
import java.util.Objects;
2627
import java.util.function.Consumer;
2728
import java.util.function.Function;
2829
import java.util.stream.Collectors;
@@ -133,17 +134,21 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
133134

134135
protected final List<String> messageHandlerAttributes = new ArrayList<>(); // NOSONAR
135136

136-
protected final Class<T> annotationType; // NOSONAR
137+
protected final Class<T> annotationType;
137138

139+
@SuppressWarnings("NullAway.Init")
138140
private ConfigurableListableBeanFactory beanFactory;
139141

142+
@SuppressWarnings("NullAway.Init")
140143
private BeanDefinitionRegistry definitionRegistry;
141144

145+
@SuppressWarnings("NullAway.Init")
142146
private ConversionService conversionService;
143147

148+
@SuppressWarnings("NullAway.Init")
144149
private volatile DestinationResolver<MessageChannel> channelResolver;
145150

146-
@SuppressWarnings(UNCHECKED)
151+
@SuppressWarnings("NullAway")
147152
public AbstractMethodAnnotationPostProcessor() {
148153
this.messageHandlerAttributes.add(SEND_TIMEOUT_ATTRIBUTE);
149154
this.annotationType =
@@ -190,7 +195,7 @@ public void processBeanDefinition(String beanName, AnnotatedBeanDefinition beanD
190195
BeanDefinition handlerBeanDefinition =
191196
resolveHandlerBeanDefinition(beanName, beanDefinition, handlerBeanType, annotations);
192197
MergedAnnotations mergedAnnotations =
193-
beanDefinition.getFactoryMethodMetadata().getAnnotations(); // NOSONAR
198+
Objects.requireNonNull(beanDefinition.getFactoryMethodMetadata()).getAnnotations();
194199

195200
if (handlerBeanDefinition != null) {
196201
if (!handlerBeanDefinition.equals(beanDefinition)) {
@@ -410,7 +415,7 @@ protected BeanDefinition resolveHandlerBeanDefinition(String beanName, Annotated
410415
if (FactoryBean.class.isAssignableFrom(classToCheck)) {
411416
classToCheck = this.beanFactory.getType(beanName);
412417
}
413-
418+
Assert.state(classToCheck != null, "No handler bean found for " + beanName);
414419
if (isClassIn(classToCheck, AbstractMessageProducingHandler.class, AbstractMessageRouter.class)) {
415420
checkMessageHandlerAttributes(beanName, annotations);
416421
return beanDefinition;
@@ -482,7 +487,7 @@ private MessageHandler annotated(Method method, MessageHandler handlerArg) {
482487
&& !AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
483488

484489
String[] interceptors =
485-
AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value(); // NOSONAR never null
490+
Objects.requireNonNull(AnnotationUtils.getAnnotation(method, IdempotentReceiver.class)).value();
486491
for (String interceptor : interceptors) {
487492
DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor();
488493
advisor.setAdviceBeanName(interceptor);
@@ -531,7 +536,7 @@ private MessageHandler adviceChain(String beanName, List<Annotation> annotations
531536
return handler;
532537
}
533538

534-
protected List<Advice> extractAdviceChain(String beanName, List<Annotation> annotations) {
539+
protected @Nullable List<Advice> extractAdviceChain(String beanName, List<Annotation> annotations) {
535540
List<Advice> adviceChain = null;
536541
String[] adviceChainNames = MessagingAnnotationUtils.resolveAttribute(annotations, ADVICE_CHAIN_ATTRIBUTE,
537542
String[].class);
@@ -564,7 +569,7 @@ else if (adviceChainBean instanceof Collection) {
564569
return adviceChain;
565570
}
566571

567-
protected AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarnings("unused") Method method,
572+
protected @Nullable AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarnings("unused") Method method,
568573
List<Annotation> annotations) {
569574

570575
AbstractEndpoint endpoint = null;
@@ -622,7 +627,7 @@ else if (inputChannel instanceof PollableChannel) {
622627
}
623628

624629
private ReactiveStreamsConsumer reactiveStreamsConsumer(MessageChannel channel, MessageHandler handler,
625-
Reactive reactive) {
630+
@Nullable Reactive reactive) {
626631

627632
ReactiveStreamsConsumer reactiveStreamsConsumer;
628633
if (handler instanceof ReactiveMessageHandlerAdapter reactiveMessageHandlerAdapter) {
@@ -646,13 +651,13 @@ private ReactiveStreamsConsumer reactiveStreamsConsumer(MessageChannel channel,
646651
return reactiveStreamsConsumer;
647652
}
648653

649-
private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, Poller poller) {
654+
private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, @Nullable Poller poller) {
650655
PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler);
651656
configurePollingEndpoint(pollingConsumer, poller);
652657
return pollingConsumer;
653658
}
654659

655-
protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, Poller poller) {
660+
protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, @Nullable Poller poller) {
656661
PollerMetadata pollerMetadata;
657662
if (poller != null) {
658663
String ref = poller.value();
@@ -704,8 +709,9 @@ protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint,
704709
}
705710

706711
private PollerMetadata configurePoller(AbstractPollingEndpoint pollingEndpoint, String triggerRef,
707-
String executorRef, String fixedDelayValue, String fixedRateValue, String maxMessagesPerPollValue,
708-
String cron, String errorChannel, String receiveTimeout) {
712+
String executorRef, @Nullable String fixedDelayValue, @Nullable String fixedRateValue,
713+
@Nullable String maxMessagesPerPollValue, @Nullable String cron, @Nullable String errorChannel,
714+
@Nullable String receiveTimeout) {
709715

710716
PollerMetadata pollerMetadata;
711717
pollerMetadata = new PollerMetadata();
@@ -736,7 +742,7 @@ else if (pollingEndpoint instanceof SourcePollingChannelAdapter) {
736742
return pollerMetadata;
737743
}
738744

739-
private void trigger(String triggerRef, String fixedDelayValue, String fixedRateValue, String cron,
745+
private void trigger(String triggerRef, @Nullable String fixedDelayValue, @Nullable String fixedRateValue, @Nullable String cron,
740746
PollerMetadata pollerMetadata) {
741747

742748
Trigger trigger = null;
@@ -815,7 +821,7 @@ protected boolean resolveAttributeToBoolean(String attribute) {
815821
return Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(attribute));
816822
}
817823

818-
protected static BeanDefinition buildLambdaMessageProcessor(ResolvableType beanType,
824+
protected static @Nullable BeanDefinition buildLambdaMessageProcessor(ResolvableType beanType,
819825
AnnotatedBeanDefinition beanDefinition) {
820826

821827
Class<?> beanClass = beanType.toClass();

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package org.springframework.integration.config;
1818

1919
import java.util.List;
20+
import java.util.Objects;
2021
import java.util.concurrent.locks.Lock;
2122
import java.util.concurrent.locks.ReentrantLock;
2223

2324
import org.aopalliance.aop.Advice;
2425
import org.apache.commons.logging.Log;
2526
import org.apache.commons.logging.LogFactory;
27+
import org.jspecify.annotations.Nullable;
2628

27-
import org.springframework.aop.framework.Advised;
2829
import org.springframework.aop.framework.AopProxyUtils;
2930
import org.springframework.beans.BeansException;
3031
import org.springframework.beans.factory.BeanFactory;
@@ -71,29 +72,34 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean<H extends MessageH
7172

7273
private final Lock initializationMonitor = new ReentrantLock();
7374

75+
@SuppressWarnings("NullAway.Init")
7476
private BeanFactory beanFactory;
7577

78+
@SuppressWarnings("NullAway.Init")
7679
private H handler;
7780

78-
private MessageChannel outputChannel;
81+
private @Nullable MessageChannel outputChannel;
7982

80-
private String outputChannelName;
83+
private @Nullable String outputChannelName;
8184

82-
private Integer order;
85+
private @Nullable Integer order;
8386

84-
private List<Advice> adviceChain;
87+
private @Nullable List<Advice> adviceChain;
8588

86-
private String componentName;
89+
private @Nullable String componentName;
8790

91+
@SuppressWarnings("NullAway.Init")
8892
private ApplicationContext applicationContext;
8993

94+
@SuppressWarnings("NullAway.Init")
9095
private String beanName;
9196

97+
@SuppressWarnings("NullAway.Init")
9298
private ApplicationEventPublisher applicationEventPublisher;
9399

94-
private DestinationResolver<MessageChannel> channelResolver;
100+
private @Nullable DestinationResolver<MessageChannel> channelResolver;
95101

96-
private Boolean async;
102+
private @Nullable Boolean async;
97103

98104
private boolean initialized;
99105

@@ -190,18 +196,14 @@ public void setComponentName(String componentName) {
190196
public H getObject() {
191197
if (this.handler == null) {
192198
this.handler = createHandlerInternal();
193-
Assert.notNull(this.handler, "failed to create MessageHandler");
194199
}
195200
return this.handler;
196201
}
197202

198203
protected final H createHandlerInternal() {
199204
this.initializationMonitor.lock();
200205
try {
201-
if (this.initialized) {
202-
// There was a problem when this method was called already
203-
return null;
204-
}
206+
Assert.state(!this.initialized, "FactoryBean already initialized");
205207
this.handler = createHandler();
206208
JavaUtils.INSTANCE
207209
.acceptIfCondition(this.handler instanceof ApplicationContextAware && this.applicationContext != null,
@@ -313,12 +315,7 @@ public boolean isSingleton() {
313315
}
314316

315317
private static Object extractTarget(Object object) {
316-
if (!(object instanceof Advised)) {
317-
return object;
318-
}
319-
else {
320-
return extractTarget(AopProxyUtils.getSingletonTarget(object));
321-
}
318+
return Objects.requireNonNullElse(AopProxyUtils.getSingletonTarget(object), object);
322319
}
323320

324321
}

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractStandardMessageHandlerFactoryBean.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
package org.springframework.integration.config;
1818

1919
import java.util.HashSet;
20+
import java.util.Objects;
2021
import java.util.Set;
2122

23+
import org.jspecify.annotations.Nullable;
24+
2225
import org.springframework.beans.factory.DisposableBean;
2326
import org.springframework.expression.Expression;
2427
import org.springframework.expression.ExpressionParser;
@@ -48,16 +51,22 @@ public abstract class AbstractStandardMessageHandlerFactoryBean
4851

4952
private static final Set<MessageHandler> REFERENCED_REPLY_PRODUCERS = new HashSet<>();
5053

54+
@SuppressWarnings("NullAway.Init")
5155
private Boolean requiresReply;
5256

57+
@SuppressWarnings("NullAway.Init")
5358
private Object targetObject;
5459

60+
@SuppressWarnings("NullAway.Init")
5561
private String targetMethodName;
5662

63+
@SuppressWarnings("NullAway.Init")
5764
private Expression expression;
5865

66+
@SuppressWarnings("NullAway.Init")
5967
private Long sendTimeout;
6068

69+
@SuppressWarnings("NullAway.Init")
6170
private MessageHandler replyHandler;
6271

6372
/**
@@ -135,8 +144,8 @@ else if (targetIsDirectReplyProducingHandler) {
135144
if (logger.isDebugEnabled()) {
136145
logger.debug("Wiring handler (" + this.targetObject + ") directly into endpoint");
137146
}
138-
checkReuse(actualHandler);
139-
postProcessReplyProducer(actualHandler);
147+
checkReuse(Objects.requireNonNull(actualHandler));
148+
postProcessReplyProducer(Objects.requireNonNull(actualHandler));
140149
handler = (MessageHandler) this.targetObject;
141150
}
142151
else {
@@ -152,7 +161,7 @@ else if (this.expression != null) {
152161
return handler;
153162
}
154163

155-
protected void checkForIllegalTarget(Object targetObject, String targetMethodName) {
164+
protected void checkForIllegalTarget(Object targetObject, @Nullable String targetMethodName) {
156165
if (targetObject instanceof AbstractReplyProducingMessageHandler
157166
&& methodIsHandleMessageOrEmpty(targetMethodName)) {
158167
/*
@@ -179,7 +188,7 @@ private void checkReuse(AbstractMessageProducingHandler replyHandler) {
179188
* @param targetMethodName the method name of the target object to invoke.
180189
* @return the method invoking {@link MessageHandler} implementation.
181190
*/
182-
protected abstract MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName);
191+
protected abstract MessageHandler createMethodInvokingHandler(Object targetObject, @Nullable String targetMethodName);
183192

184193
protected MessageHandler createExpressionEvaluatingHandler(Expression expression) {
185194
throw new UnsupportedOperationException(getClass().getName() + " does not support expressions.");
@@ -193,7 +202,7 @@ protected MessageHandler createDefaultHandler() {
193202
throw new IllegalArgumentException("Exactly one of the 'targetObject' or 'expression' property is required.");
194203
}
195204

196-
protected boolean methodIsHandleMessageOrEmpty(String targetMethodName) {
205+
protected boolean methodIsHandleMessageOrEmpty(@Nullable String targetMethodName) {
197206
return (!StringUtils.hasText(targetMethodName)
198207
|| "handleMessage".equals(targetMethodName));
199208
}

spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,54 @@
5656
*/
5757
public class AggregatorFactoryBean extends AbstractSimpleMessageHandlerFactoryBean<AggregatingMessageHandler> {
5858

59+
@SuppressWarnings("NullAway.Init")
5960
private Object processorBean;
6061

61-
private String methodName;
62+
private @Nullable String methodName;
6263

63-
private Boolean expireGroupsUponCompletion;
64+
private @Nullable Boolean expireGroupsUponCompletion;
6465

65-
private Long sendTimeout;
66+
private @Nullable Long sendTimeout;
6667

67-
private String outputChannelName;
68+
private @Nullable String outputChannelName;
6869

69-
private LockRegistry<?> lockRegistry;
70+
private @Nullable LockRegistry<?> lockRegistry;
7071

71-
private MessageGroupStore messageStore;
72+
private @Nullable MessageGroupStore messageStore;
7273

73-
private CorrelationStrategy correlationStrategy;
74+
private @Nullable CorrelationStrategy correlationStrategy;
7475

75-
private ReleaseStrategy releaseStrategy;
76+
private @Nullable ReleaseStrategy releaseStrategy;
7677

77-
private Expression groupTimeoutExpression;
78+
private @Nullable Expression groupTimeoutExpression;
7879

79-
private List<Advice> forceReleaseAdviceChain;
80+
private @Nullable List<Advice> forceReleaseAdviceChain;
8081

81-
private TaskScheduler taskScheduler;
82+
private @Nullable TaskScheduler taskScheduler;
8283

83-
private MessageChannel discardChannel;
84+
private @Nullable MessageChannel discardChannel;
8485

85-
private String discardChannelName;
86+
private @Nullable String discardChannelName;
8687

87-
private Boolean sendPartialResultOnExpiry;
88+
private @Nullable Boolean sendPartialResultOnExpiry;
8889

89-
private Boolean discardIndividuallyOnExpiry;
90+
private @Nullable Boolean discardIndividuallyOnExpiry;
9091

91-
private Long minimumTimeoutForEmptyGroups;
92+
private @Nullable Long minimumTimeoutForEmptyGroups;
9293

93-
private Boolean expireGroupsUponTimeout;
94+
private @Nullable Boolean expireGroupsUponTimeout;
9495

95-
private Boolean popSequence;
96+
private @Nullable Boolean popSequence;
9697

97-
private Boolean releaseLockBeforeSend;
98+
private @Nullable Boolean releaseLockBeforeSend;
9899

99-
private Long expireTimeout;
100+
private @Nullable Long expireTimeout;
100101

101-
private Long expireDuration;
102+
private @Nullable Long expireDuration;
102103

103-
private Function<MessageGroup, Map<String, Object>> headersFunction;
104+
private @Nullable Function<MessageGroup, Map<String, Object>> headersFunction;
104105

105-
private BiFunction<Message<?>, String, String> groupConditionSupplier;
106+
private @Nullable BiFunction<Message<?>, String, String> groupConditionSupplier;
106107

107108
public void setProcessorBean(Object processorBean) {
108109
this.processorBean = processorBean;

0 commit comments

Comments
 (0)