Skip to content

Commit 10af742

Browse files
committed
Remove unnecessary Nullable annotations
* Set AppContext to not be nullable * Consumer's inbound channels are never null. Update to remove nullable * Update outbound channels so they are not nullable * Use local variable trick to work past Nullables inability to see a new above return value * Add contract to channelToBeanName in IntegrationGraphServer
1 parent 1a09b5a commit 10af742

12 files changed

+29
-29
lines changed

spring-integration-core/src/main/java/org/springframework/integration/graph/CompositeMessageHandlerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class CompositeMessageHandlerNode extends MessageHandlerNode {
3535

3636
private final List<InnerHandler> handlers = new ArrayList<>();
3737

38-
public CompositeMessageHandlerNode(int nodeId, String name, MessageHandler handler, @Nullable String input, @Nullable String output,
38+
public CompositeMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input, @Nullable String output,
3939
List<InnerHandler> handlers) {
4040

4141
super(nodeId, name, handler, input, output);

spring-integration-core/src/main/java/org/springframework/integration/graph/DiscardingMessageHandlerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class DiscardingMessageHandlerNode extends MessageHandlerNode {
3232

3333
private final @Nullable String discards;
3434

35-
public DiscardingMessageHandlerNode(int nodeId, String name, MessageHandler handler, @Nullable String input,
35+
public DiscardingMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input,
3636
@Nullable String output, @Nullable String discards) {
3737

3838
super(nodeId, name, handler, input, output);

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableCompositeMessageHandlerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ErrorCapableCompositeMessageHandlerNode extends CompositeMessageHan
3636
private final @Nullable String errors;
3737

3838
public ErrorCapableCompositeMessageHandlerNode(int nodeId, String name, CompositeMessageHandler handler,
39-
@Nullable String input, @Nullable String output, @Nullable String errors, List<InnerHandler> handlers) {
39+
String input, @Nullable String output, @Nullable String errors, List<InnerHandler> handlers) {
4040

4141
super(nodeId, name, handler, input, output, handlers);
4242
this.errors = errors;

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableDiscardingMessageHandlerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ErrorCapableDiscardingMessageHandlerNode extends DiscardingMessageH
3333

3434
private final @Nullable String errors;
3535

36-
public ErrorCapableDiscardingMessageHandlerNode(int nodeId, String name, MessageHandler handler, @Nullable String input,
36+
public ErrorCapableDiscardingMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input,
3737
@Nullable String output, @Nullable String discards, @Nullable String errors) {
3838

3939
super(nodeId, name, handler, input, output, discards);

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableMessageHandlerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ErrorCapableMessageHandlerNode extends MessageHandlerNode implement
3131

3232
private final @Nullable String errors;
3333

34-
public ErrorCapableMessageHandlerNode(int nodeId, String name, MessageHandler handler, @Nullable String input,
34+
public ErrorCapableMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input,
3535
@Nullable String output, @Nullable String errors) {
3636

3737
super(nodeId, name, handler, input, output);

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableRoutingNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ErrorCapableRoutingNode extends RoutingMessageHandlerNode implement
3535

3636
private final @Nullable String errors;
3737

38-
public ErrorCapableRoutingNode(int nodeId, String name, MessageHandler handler, @Nullable String input, @Nullable String output,
38+
public ErrorCapableRoutingNode(int nodeId, String name, MessageHandler handler, String input, @Nullable String output,
3939
@Nullable String errors, Collection<String> routes) {
4040

4141
super(nodeId, name, handler, input, output, routes);

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.springframework.integration.support.management.MappingMessageRouterManagement;
5656
import org.springframework.integration.support.management.micrometer.MicrometerMetricsCaptorConfiguration;
5757
import org.springframework.integration.support.utils.IntegrationUtils;
58+
import org.springframework.lang.Contract;
5859
import org.springframework.messaging.MessageChannel;
5960
import org.springframework.messaging.MessageHandler;
6061
import org.springframework.messaging.PollableChannel;
@@ -81,7 +82,8 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
8182

8283
private @Nullable MicrometerNodeEnhancer micrometerEnhancer;
8384

84-
private @Nullable ApplicationContext applicationContext;
85+
@SuppressWarnings("NullAway.Init")
86+
private ApplicationContext applicationContext;
8587

8688
private volatile @Nullable Graph graph;
8789

@@ -133,20 +135,20 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
133135
* @return the graph.
134136
* @see #rebuild()
135137
*/
136-
@SuppressWarnings("NullAway") // Dataflow analysis limitation
137138
public Graph getGraph() {
138139
if (this.graph == null) {
139140
this.lock.lock();
140141
try {
141142
if (this.graph == null) {
142-
buildGraph();
143+
this.graph = buildGraph();
143144
}
144145
}
145146
finally {
146147
this.lock.unlock();
147148
}
148149
}
149-
return this.graph;
150+
var graph = this.graph;
151+
return graph;
150152
}
151153

152154
/**
@@ -175,9 +177,6 @@ public Graph rebuild() {
175177
* @since 5.1
176178
*/
177179
protected <T> Map<String, T> getBeansOfType(Class<T> type) {
178-
if (this.applicationContext == null) {
179-
throw new IllegalStateException("ApplicationContext is not set");
180-
}
181180
return this.applicationContext.getBeansOfType(type, true, false);
182181
}
183182

@@ -190,11 +189,7 @@ private <T extends IntegrationNode> T enhance(T node) {
190189
}
191190
}
192191

193-
@SuppressWarnings("NullAway") // Dataflow analysis limitation
194192
private Graph buildGraph() {
195-
if (this.applicationContext == null) {
196-
throw new IllegalStateException("ApplicationContext is not set");
197-
}
198193
if (this.micrometerEnhancer == null && MicrometerMetricsCaptorConfiguration.METER_REGISTRY_PRESENT) {
199194
this.micrometerEnhancer = new MicrometerNodeEnhancer(this.applicationContext);
200195
}
@@ -221,8 +216,9 @@ private Graph buildGraph() {
221216
gateways(nodes, links, channelNodes);
222217
producers(nodes, links, channelNodes);
223218
consumers(nodes, links, channelNodes);
224-
this.graph = new Graph(descriptor, nodes, links);
225-
return this.graph;
219+
var graph = new Graph(descriptor, nodes, links);
220+
this.graph = graph;
221+
return graph;
226222
}
227223

228224
private Map<String, MessageChannelNode> channels(Collection<IntegrationNode> nodes) {
@@ -416,6 +412,7 @@ MessageGatewayNode gatewayNode(String name, MessagingGatewaySupport gateway) {
416412
return new MessageGatewayNode(this.nodeId.incrementAndGet(), name, gateway, requestChannel, errorChannel);
417413
}
418414

415+
@Contract("null -> null; !null -> !null")
419416
private @Nullable String channelToBeanName(@Nullable MessageChannel messageChannel) {
420417
return messageChannel instanceof NamedComponent namedComponent
421418
? namedComponent.getBeanName()
@@ -425,6 +422,7 @@ MessageGatewayNode gatewayNode(String name, MessagingGatewaySupport gateway) {
425422
MessageProducerNode producerNode(String name, MessageProducerSupport producer) {
426423
String errorChannel = channelToBeanName(producer.getErrorChannel());
427424
String outputChannel = channelToBeanName(producer.getOutputChannel());
425+
Assert.state(outputChannel != null, "'outputChannel' must not be null");
428426
return new MessageProducerNode(this.nodeId.incrementAndGet(), name, producer, outputChannel, errorChannel);
429427
}
430428

spring-integration-core/src/main/java/org/springframework/integration/graph/MessageHandlerNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@
3333
*/
3434
public class MessageHandlerNode extends EndpointNode implements SendTimersAware {
3535

36-
private final @Nullable String input;
36+
private final String input;
3737

3838
private @Nullable Supplier<SendTimers> sendTimers;
3939

40-
public MessageHandlerNode(int nodeId, String name, MessageHandler handler, @Nullable String input, @Nullable String output) {
40+
public MessageHandlerNode(int nodeId, String name, MessageHandler handler, String input, @Nullable String output) {
4141
super(nodeId, name, handler, output);
4242
this.input = input;
4343
}
4444

45-
public @Nullable String getInput() {
45+
public String getInput() {
4646
return this.input;
4747
}
4848

49-
@Nullable
50-
public SendTimers getSendTimers() {
49+
public @Nullable SendTimers getSendTimers() {
5150
return this.sendTimers != null ? this.sendTimers.get() : null;
5251
}
5352

spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public class MessageProducerNode extends ErrorCapableEndpointNode {
3232

33-
public MessageProducerNode(int nodeId, String name, MessageProducerSupport producer, @Nullable String output, @Nullable String errors) {
33+
public MessageProducerNode(int nodeId, String name, MessageProducerSupport producer, String output, @Nullable String errors) {
3434
super(nodeId, name, producer, output, errors);
3535
}
3636

spring-integration-core/src/main/java/org/springframework/integration/graph/MessageSourceNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class MessageSourceNode extends ErrorCapableEndpointNode implements Recei
3535

3636
private @Nullable Supplier<ReceiveCounters> receiveCounters;
3737

38-
public MessageSourceNode(int nodeId, String name, MessageSource<?> messageSource, @Nullable String output, @Nullable String errors) {
38+
public MessageSourceNode(int nodeId, String name, MessageSource<?> messageSource, String output, @Nullable String errors) {
3939
super(nodeId, name, messageSource, output, errors);
4040
}
4141

0 commit comments

Comments
 (0)