Skip to content

Commit 211ae28

Browse files
artembilancppwfs
authored andcommitted
spring-projectsGH-10083: Apply Nullability into dsl package
Related to: spring-projects#10083 * Fix all the reported issues and IDE suggestions * Also, improve Nullability in the `TailAdapterSpec` and couple DSL Specs in JDBC module according to a new Nullability rules in the core `dsl` package * Make `IntegrationComponentSpec.id()` as not-null * Fix all the affected classes to deal with not-null or ensure they provide not-null
1 parent c30df66 commit 211ae28

File tree

49 files changed

+260
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+260
-272
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AbstractMessageListenerContainerSpec.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.concurrent.Executor;
2121

2222
import org.aopalliance.aop.Advice;
23-
import org.jspecify.annotations.Nullable;
2423

2524
import org.springframework.amqp.core.AcknowledgeMode;
2625
import org.springframework.amqp.core.MessagePostProcessor;
@@ -56,7 +55,7 @@ public AbstractMessageListenerContainerSpec(C listenerContainer) {
5655
}
5756

5857
@Override
59-
public S id(@Nullable String id) { // NOSONAR - not useless, increases visibility
58+
public S id(String id) {
6059
return super.id(id);
6160
}
6261

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/Amqp.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.integration.amqp.dsl;
1818

19-
import org.jspecify.annotations.Nullable;
20-
2119
import org.springframework.amqp.core.AmqpTemplate;
2220
import org.springframework.amqp.core.Queue;
2321
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
@@ -274,7 +272,7 @@ public static AmqpAsyncOutboundGatewaySpec asyncOutboundGateway(AsyncRabbitTempl
274272
public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableChannel(
275273
ConnectionFactory connectionFactory) {
276274

277-
return pollableChannel(null, connectionFactory);
275+
return new AmqpPollableMessageChannelSpec<>(connectionFactory);
278276
}
279277

280278
/**
@@ -283,7 +281,7 @@ public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableCha
283281
* @param connectionFactory the connectionFactory.
284282
* @return the AmqpPollableMessageChannelSpec.
285283
*/
286-
public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableChannel(@Nullable String id,
284+
public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableChannel(String id,
287285
ConnectionFactory connectionFactory) {
288286

289287
AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> spec =
@@ -297,7 +295,7 @@ public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableCha
297295
* @return the AmqpMessageChannelSpec.
298296
*/
299297
public static AmqpMessageChannelSpec<?, ?> channel(ConnectionFactory connectionFactory) {
300-
return channel(null, connectionFactory);
298+
return new AmqpMessageChannelSpec<>(connectionFactory);
301299
}
302300

303301
/**
@@ -306,7 +304,7 @@ public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableCha
306304
* @param connectionFactory the connectionFactory.
307305
* @return the AmqpMessageChannelSpec.
308306
*/
309-
public static AmqpMessageChannelSpec<?, ?> channel(@Nullable String id, ConnectionFactory connectionFactory) {
307+
public static AmqpMessageChannelSpec<?, ?> channel(String id, ConnectionFactory connectionFactory) {
310308
return new AmqpMessageChannelSpec<>(connectionFactory)
311309
.id(id);
312310
}
@@ -317,7 +315,7 @@ public static AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> pollableCha
317315
* @return the AmqpPublishSubscribeMessageChannelSpec.
318316
*/
319317
public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(ConnectionFactory connectionFactory) {
320-
return publishSubscribeChannel(null, connectionFactory);
318+
return new AmqpPublishSubscribeMessageChannelSpec(connectionFactory);
321319
}
322320

323321
/**
@@ -326,7 +324,7 @@ public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(Con
326324
* @param connectionFactory the connectionFactory.
327325
* @return the AmqpPublishSubscribeMessageChannelSpec.
328326
*/
329-
public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(@Nullable String id,
327+
public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(String id,
330328
ConnectionFactory connectionFactory) {
331329

332330
return new AmqpPublishSubscribeMessageChannelSpec(connectionFactory).id(id);

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpPollableMessageChannelSpec.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.integration.amqp.dsl;
1818

19-
import org.jspecify.annotations.Nullable;
20-
2119
import org.springframework.amqp.core.MessageDeliveryMode;
2220
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
2321
import org.springframework.amqp.rabbit.support.MessagePropertiesConverter;
@@ -29,7 +27,6 @@
2927
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
3028
import org.springframework.integration.dsl.MessageChannelSpec;
3129
import org.springframework.util.Assert;
32-
import org.springframework.util.StringUtils;
3330

3431
/**
3532
* A {@link MessageChannelSpec} for a {@link AbstractAmqpChannel}s.
@@ -66,10 +63,8 @@ protected AmqpPollableMessageChannelSpec(ConnectionFactory connectionFactory) {
6663
}
6764

6865
@Override
69-
protected S id(@Nullable String id) {
70-
if (StringUtils.hasText(id)) {
71-
this.amqpChannelFactoryBean.setBeanName(id);
72-
}
66+
protected S id(String id) {
67+
this.amqpChannelFactoryBean.setBeanName(id);
7368
return super.id(id);
7469
}
7570

spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
public class AggregatorSpec extends CorrelationHandlerSpec<AggregatorSpec, AggregatingMessageHandler> {
4242

43-
private Function<MessageGroup, Map<String, Object>> headersFunction;
43+
private @Nullable Function<MessageGroup, Map<String, Object>> headersFunction;
4444

4545
protected AggregatorSpec() {
4646
super(new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()));
@@ -123,7 +123,7 @@ public AggregatorSpec headersFunction(Function<MessageGroup, Map<String, Object>
123123
}
124124

125125
@Override
126-
public Map<Object, String> getComponentsToRegister() {
126+
public Map<Object, @Nullable String> getComponentsToRegister() {
127127
if (this.headersFunction != null) {
128128
MessageGroupProcessor outputProcessor = this.handler.getOutputProcessor();
129129
if (outputProcessor instanceof AbstractAggregatingMessageGroupProcessor abstractAggregatingMessageGroupProcessor) {

spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ public class BarrierSpec extends ConsumerEndpointSpec<BarrierSpec, BarrierMessag
4545
private CorrelationStrategy correlationStrategy =
4646
new HeaderAttributeCorrelationStrategy(IntegrationMessageHeaderAccessor.CORRELATION_ID);
4747

48-
@Nullable
49-
private MessageChannel discardChannel;
48+
private @Nullable MessageChannel discardChannel;
5049

51-
@Nullable
52-
private String discardChannelName;
50+
private @Nullable String discardChannelName;
5351

54-
@Nullable
55-
private Long triggerTimeout;
52+
private @Nullable Long triggerTimeout;
5653

5754
protected BarrierSpec(long timeout) {
58-
super(null);
5955
this.timeout = timeout;
6056
}
6157

spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import reactor.core.publisher.Flux;
3030
import reactor.util.function.Tuple2;
3131

32-
import org.springframework.aop.framework.Advised;
3332
import org.springframework.aop.framework.AopInfrastructureBean;
3433
import org.springframework.aop.support.AopUtils;
3534
import org.springframework.beans.BeansException;
@@ -130,15 +129,15 @@ public abstract class BaseIntegrationFlowDefinition<B extends BaseIntegrationFlo
130129

131130
protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); //NOSONAR - final
132131

133-
protected final Map<Object, String> integrationComponents = new LinkedHashMap<>(); //NOSONAR - final
132+
protected final Map<Object, @Nullable String> integrationComponents = new LinkedHashMap<>(); //NOSONAR - final
134133

135-
private MessageChannel currentMessageChannel;
134+
private @Nullable MessageChannel currentMessageChannel;
136135

137-
private Object currentComponent;
136+
private @Nullable Object currentComponent;
138137

139138
private boolean implicitChannel;
140139

141-
private StandardIntegrationFlow integrationFlow;
140+
private @Nullable StandardIntegrationFlow integrationFlow;
142141

143142
protected BaseIntegrationFlowDefinition() {
144143
}
@@ -152,14 +151,14 @@ protected B addComponent(Object component, @Nullable String beanName) {
152151
return _this();
153152
}
154153

155-
protected B addComponents(Map<Object, String> components) {
154+
protected B addComponents(Map<Object, @Nullable String> components) {
156155
if (!CollectionUtils.isEmpty(components)) {
157156
this.integrationComponents.putAll(components);
158157
}
159158
return _this();
160159
}
161160

162-
protected Map<Object, String> getIntegrationComponents() {
161+
protected Map<Object, @Nullable String> getIntegrationComponents() {
163162
return this.integrationComponents;
164163
}
165164

@@ -168,8 +167,7 @@ protected B currentComponent(@Nullable Object component) {
168167
return _this();
169168
}
170169

171-
@Nullable
172-
protected Object getCurrentComponent() {
170+
protected @Nullable Object getCurrentComponent() {
173171
return this.currentComponent;
174172
}
175173

@@ -178,8 +176,7 @@ protected B currentMessageChannel(@Nullable MessageChannel currentMessageChannel
178176
return _this();
179177
}
180178

181-
@Nullable
182-
protected MessageChannel getCurrentMessageChannel() {
179+
protected @Nullable MessageChannel getCurrentMessageChannel() {
183180
return this.currentMessageChannel;
184181
}
185182

@@ -1591,7 +1588,7 @@ public B resequence(@Nullable Consumer<ResequencerSpec> resequencer) {
15911588
* @return the current {@link BaseIntegrationFlowDefinition}.
15921589
*/
15931590
public B aggregate() {
1594-
return aggregate((Consumer<AggregatorSpec>) null);
1591+
return aggregate(null);
15951592
}
15961593

15971594
/**
@@ -1829,8 +1826,8 @@ protected <R extends AbstractMessageRouter, S extends AbstractRouterSpec<? super
18291826
BridgeHandler bridgeHandler = new BridgeHandler();
18301827
boolean registerSubflowBridge = false;
18311828

1832-
Map<Object, String> componentsToRegister = null;
1833-
Map<Object, String> routerComponents = routerSpec.getComponentsToRegister();
1829+
Map<Object, @Nullable String> componentsToRegister = null;
1830+
Map<Object, @Nullable String> routerComponents = routerSpec.getComponentsToRegister();
18341831
if (!CollectionUtils.isEmpty(routerComponents)) {
18351832
componentsToRegister = new LinkedHashMap<>(routerComponents);
18361833
routerComponents.clear();
@@ -2571,7 +2568,7 @@ protected <T> Publisher<Message<T>> toReactivePublisher() {
25712568
protected <T> Publisher<Message<T>> toReactivePublisher(boolean autoStartOnSubscribe) {
25722569
MessageChannel channelForPublisher = getCurrentMessageChannel();
25732570
Publisher<Message<T>> publisher;
2574-
Map<Object, String> components = getIntegrationComponents();
2571+
Map<Object, @Nullable String> components = getIntegrationComponents();
25752572
if (channelForPublisher instanceof Publisher) {
25762573
publisher = (Publisher<Message<T>>) channelForPublisher;
25772574
}
@@ -2700,7 +2697,7 @@ protected StandardIntegrationFlow get() {
27002697
"EIP-method in the 'IntegrationFlow' definition.");
27012698
}
27022699

2703-
Map<Object, String> components = getIntegrationComponents();
2700+
Map<Object, @Nullable String> components = getIntegrationComponents();
27042701
if (components.size() == 1) {
27052702
Object currComponent = getCurrentComponent();
27062703
if (currComponent != null) {
@@ -2736,17 +2733,8 @@ protected void checkReuse(MessageProducer replyHandler) {
27362733
REFERENCED_REPLY_PRODUCERS.add(replyHandler);
27372734
}
27382735

2739-
@Nullable
2740-
protected static Object extractProxyTarget(@Nullable Object target) {
2741-
if (!(target instanceof Advised advised)) {
2742-
return target;
2743-
}
2744-
try {
2745-
return extractProxyTarget(advised.getTargetSource().getTarget());
2746-
}
2747-
catch (Exception e) {
2748-
throw new BeanCreationException("Could not extract target", e);
2749-
}
2736+
protected static @Nullable Object extractProxyTarget(@Nullable Object target) {
2737+
return IntegrationFlow.extractProxyTarget(target);
27502738
}
27512739

27522740
public static final class ReplyProducerCleaner implements DestructionAwareBeanPostProcessor, AopInfrastructureBean {

spring-integration-core/src/main/java/org/springframework/integration/dsl/BroadcastPublishSubscribeSpec.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.integration.channel.BroadcastCapableChannel;
2325
import org.springframework.messaging.MessageChannel;
2426
import org.springframework.util.Assert;
@@ -36,7 +38,7 @@ public class BroadcastPublishSubscribeSpec
3638
extends IntegrationComponentSpec<BroadcastPublishSubscribeSpec, BroadcastCapableChannel>
3739
implements ComponentsRegistration {
3840

39-
private final Map<Object, String> subscriberFlows = new LinkedHashMap<>();
41+
private final Map<Object, @Nullable String> subscriberFlows = new LinkedHashMap<>();
4042

4143
private int order;
4244

@@ -74,7 +76,7 @@ public BroadcastPublishSubscribeSpec subscribe(IntegrationFlow subFlow) {
7476
}
7577

7678
@Override
77-
public Map<Object, String> getComponentsToRegister() {
79+
public Map<Object, @Nullable String> getComponentsToRegister() {
7880
return this.subscriberFlows;
7981
}
8082

spring-integration-core/src/main/java/org/springframework/integration/dsl/ConsumerEndpointSpec.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ public abstract class ConsumerEndpointSpec<S extends ConsumerEndpointSpec<S, H>,
7474
@Nullable
7575
private Boolean async;
7676

77-
@Nullable
78-
private String[] notPropagatedHeaders;
77+
private String @Nullable [] notPropagatedHeaders;
78+
79+
protected ConsumerEndpointSpec() {
80+
super(new ConsumerEndpointFactoryBean());
81+
}
7982

80-
protected ConsumerEndpointSpec(@Nullable H messageHandler) {
83+
protected ConsumerEndpointSpec(H messageHandler) {
8184
super(messageHandler, new ConsumerEndpointFactoryBean());
8285
}
8386

@@ -373,6 +376,7 @@ protected Tuple2<ConsumerEndpointFactoryBean, H> doGet() {
373376
.acceptIfNotEmpty(this.adviceChain, producingMessageHandler::setAdviceChain);
374377
}
375378

379+
Assert.state(this.handler != null, "'this.handler' must not be null.");
376380
this.endpointFactoryBean.setHandler(this.handler);
377381
return super.doGet();
378382
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,25 @@ public abstract class EndpointSpec<S extends EndpointSpec<S, F, H>, F extends Be
4949
extends IntegrationComponentSpec<S, Tuple2<F, H>>
5050
implements ComponentsRegistration {
5151

52-
protected final Map<Object, String> componentsToRegister = new LinkedHashMap<>(); // NOSONAR final
52+
protected final Map<Object, @Nullable String> componentsToRegister = new LinkedHashMap<>(); // NOSONAR final
5353

5454
protected final F endpointFactoryBean; // NOSONAR final
5555

56-
protected H handler; // NOSONAR
56+
@SuppressWarnings("NullAway.Init")
57+
protected H handler;
5758

58-
protected EndpointSpec(@Nullable H handler, F endpointFactoryBean) {
59+
protected EndpointSpec(F endpointFactoryBean) {
60+
this.endpointFactoryBean = endpointFactoryBean;
61+
}
62+
63+
protected EndpointSpec(H handler, F endpointFactoryBean) {
5964
this.endpointFactoryBean = endpointFactoryBean;
6065
this.handler = handler;
6166
}
6267

6368
@Override
64-
public S id(@Nullable String id) {
65-
if (id != null) {
66-
this.endpointFactoryBean.setBeanName(id);
67-
}
69+
public S id(String id) {
70+
this.endpointFactoryBean.setBeanName(id);
6871
return super.id(id);
6972
}
7073

@@ -85,7 +88,7 @@ public S poller(Function<PollerFactory, PollerSpec> pollers) {
8588
* @see PollerSpec
8689
*/
8790
public S poller(PollerSpec pollerMetadataSpec) {
88-
Map<Object, String> components = pollerMetadataSpec.getComponentsToRegister();
91+
Map<Object, @Nullable String> components = pollerMetadataSpec.getComponentsToRegister();
8992
this.componentsToRegister.putAll(components);
9093
return poller(pollerMetadataSpec.getObject());
9194
}
@@ -122,17 +125,14 @@ public S poller(PollerSpec pollerMetadataSpec) {
122125
public abstract S role(String role);
123126

124127
@Override
125-
public Map<Object, String> getComponentsToRegister() {
128+
public Map<Object, @Nullable String> getComponentsToRegister() {
126129
return this.componentsToRegister;
127130
}
128131

129132
@Override
130133
protected Tuple2<F, H> doGet() {
131-
return Tuples.of(this.endpointFactoryBean, this.handler);
132-
}
133-
134-
protected void assertHandler() {
135134
Assert.state(this.handler != null, "'this.handler' must not be null.");
135+
return Tuples.of(this.endpointFactoryBean, this.handler);
136136
}
137137

138138
/**

spring-integration-core/src/main/java/org/springframework/integration/dsl/FilterEndpointSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected FilterEndpointSpec(MessageFilter messageFilter) {
3535
/**
3636
* The default value is <code>false</code> meaning that rejected
3737
* Messages will be quietly dropped or sent to the discard channel if
38-
* available. Typically this value would not be <code>true</code> when
38+
* available. Typically, this value would not be <code>true</code> when
3939
* a discard channel is provided, but if so, it will still apply
4040
* (in such a case, the Message will be sent to the discard channel,
4141
* and <em>then</em> the exception will be thrown).

0 commit comments

Comments
 (0)