Skip to content

Commit d63dd26

Browse files
authored
GH-10083: Migrate ZeroMQ module to Jspecify
Related to: #10083 - Replaced `org.springframework.lang.Nullable` with `org.jspecify.annotations.Nullable` * Complete ZeroMQ module migration to JSpecify - Migrate `package-info.java` files to use `@NullMarked` annotation - Add `@SuppressWarnings("NullAway.Init")` for fields initialized in lifecycle methods * Fix NullAway violations in ZeroMqChannel - Extract `this.zeroMqProxy` to local variable inside `Mono.defer()` block Signed-off-by: Jooyoung Pyoung <[email protected]>
1 parent 260073d commit d63dd26

File tree

9 files changed

+28
-19
lines changed

9 files changed

+28
-19
lines changed

spring-integration-zeromq/src/main/java/org/springframework/integration/zeromq/ZeroMqProxy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626

2727
import org.apache.commons.logging.Log;
2828
import org.apache.commons.logging.LogFactory;
29+
import org.jspecify.annotations.Nullable;
2930
import org.zeromq.SocketType;
3031
import org.zeromq.ZContext;
3132
import org.zeromq.ZMQ;
@@ -35,7 +36,6 @@
3536
import org.springframework.beans.factory.InitializingBean;
3637
import org.springframework.context.SmartLifecycle;
3738
import org.springframework.core.task.SimpleAsyncTaskExecutor;
38-
import org.springframework.lang.Nullable;
3939
import org.springframework.util.Assert;
4040

4141
/**
@@ -82,8 +82,10 @@ public class ZeroMqProxy implements InitializingBean, SmartLifecycle, BeanNameAw
8282

8383
private final AtomicInteger backendPort = new AtomicInteger();
8484

85+
@SuppressWarnings("NullAway.Init")
8586
private String controlAddress;
8687

88+
@SuppressWarnings("NullAway.Init")
8789
private Executor proxyExecutor;
8890

8991
@Nullable
@@ -97,6 +99,7 @@ public class ZeroMqProxy implements InitializingBean, SmartLifecycle, BeanNameAw
9799
@Nullable
98100
private String captureAddress;
99101

102+
@SuppressWarnings("NullAway.Init")
100103
private String beanName;
101104

102105
private boolean autoStartup = true;

spring-integration-zeromq/src/main/java/org/springframework/integration/zeromq/channel/ZeroMqChannel.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Consumer;
2424
import java.util.function.Supplier;
2525

26+
import org.jspecify.annotations.Nullable;
2627
import org.zeromq.SocketType;
2728
import org.zeromq.ZContext;
2829
import org.zeromq.ZMQ;
@@ -36,7 +37,6 @@
3637
import org.springframework.integration.mapping.BytesMessageMapper;
3738
import org.springframework.integration.support.json.EmbeddedJsonHeadersMessageMapper;
3839
import org.springframework.integration.zeromq.ZeroMqProxy;
39-
import org.springframework.lang.Nullable;
4040
import org.springframework.messaging.Message;
4141
import org.springframework.messaging.MessageHandler;
4242
import org.springframework.messaging.SubscribableChannel;
@@ -66,6 +66,7 @@
6666
* concurrency primitives for multi-publisher(subscriber) communication within the same application.
6767
*
6868
* @author Artem Bilan
69+
* @author Jooyoung Pyoung
6970
*
7071
* @since 5.4
7172
*/
@@ -142,19 +143,19 @@ public ZeroMqChannel(ZContext context, boolean pubSub) {
142143
this.subscriberData = prepareSubscriberDataFlux();
143144
}
144145

145-
@SuppressWarnings("this-escape")
146146
private Mono<Integer> prepareProxyMono() {
147147
return Mono.defer(() -> {
148-
if (this.zeroMqProxy != null) {
149-
return Mono.fromCallable(() -> this.zeroMqProxy.getBackendPort())
148+
ZeroMqProxy zeroMqProxyToUse = this.zeroMqProxy;
149+
if (zeroMqProxyToUse != null) {
150+
return Mono.fromCallable(zeroMqProxyToUse::getBackendPort)
150151
.filter((proxyPort) -> proxyPort > 0)
151152
.repeatWhenEmpty(100, (repeat) -> repeat.delayElements(Duration.ofMillis(100))) // NOSONAR
152153
.doOnNext((proxyPort) ->
153-
setConnectUrl("tcp://localhost:" + this.zeroMqProxy.getFrontendPort() +
154-
':' + this.zeroMqProxy.getBackendPort()))
154+
setConnectUrl("tcp://localhost:" + zeroMqProxyToUse.getFrontendPort() +
155+
':' + zeroMqProxyToUse.getBackendPort()))
155156
.doOnError((error) ->
156157
logger.error(error,
157-
() -> "The provided '" + this.zeroMqProxy + "' has not been started"));
158+
() -> "The provided '" + zeroMqProxyToUse + "' has not been started"));
158159
}
159160
else {
160161
return Mono.empty();
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides classes for message channels support over ZeroMQ.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.zeromq.channel;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Provides classes for supporting ZeroMQ component via Java DSL.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@org.jspecify.annotations.NullMarked
65
package org.springframework.integration.zeromq.dsl;

spring-integration-zeromq/src/main/java/org/springframework/integration/zeromq/inbound/ZeroMqMessageProducer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.atomic.AtomicInteger;
2525
import java.util.function.Consumer;
2626

27+
import org.jspecify.annotations.Nullable;
2728
import org.zeromq.SocketType;
2829
import org.zeromq.ZContext;
2930
import org.zeromq.ZFrame;
@@ -43,7 +44,6 @@
4344
import org.springframework.integration.zeromq.ZeroMqUtils;
4445
import org.springframework.jmx.export.annotation.ManagedOperation;
4546
import org.springframework.jmx.export.annotation.ManagedResource;
46-
import org.springframework.lang.Nullable;
4747
import org.springframework.messaging.Message;
4848
import org.springframework.messaging.converter.MessageConverter;
4949
import org.springframework.util.Assert;
@@ -77,6 +77,7 @@ public class ZeroMqMessageProducer extends MessageProducerSupport {
7777

7878
private final SocketType socketType;
7979

80+
@SuppressWarnings("NullAway.Init")
8081
private InboundMessageMapper<byte[]> messageMapper;
8182

8283
private Consumer<ZMQ.Socket> socketConfigurer = (socket) -> {
@@ -91,6 +92,7 @@ public class ZeroMqMessageProducer extends MessageProducerSupport {
9192
@Nullable
9293
private String connectUrl;
9394

95+
@SuppressWarnings("NullAway.Init")
9496
private volatile Mono<ZMQ.Socket> socketMono;
9597

9698
private volatile boolean unwrapTopic = true;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides classes for inbound channel adapters over ZeroMQ.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.zeromq.inbound;

spring-integration-zeromq/src/main/java/org/springframework/integration/zeromq/outbound/ZeroMqMessageHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import java.util.function.Consumer;
2323
import java.util.function.Supplier;
2424

25+
import org.jspecify.annotations.Nullable;
2526
import org.zeromq.SocketType;
2627
import org.zeromq.ZContext;
2728
import org.zeromq.ZFrame;
@@ -45,7 +46,6 @@
4546
import org.springframework.integration.support.converter.ConfigurableCompositeMessageConverter;
4647
import org.springframework.integration.support.management.ManageableLifecycle;
4748
import org.springframework.integration.zeromq.ZeroMqUtils;
48-
import org.springframework.lang.Nullable;
4949
import org.springframework.messaging.Message;
5050
import org.springframework.messaging.converter.MessageConverter;
5151
import org.springframework.util.Assert;
@@ -77,19 +77,23 @@ public class ZeroMqMessageHandler extends AbstractReactiveMessageHandler
7777

7878
private final Scheduler publisherScheduler = Schedulers.newSingle("zeroMqMessageHandlerScheduler");
7979

80+
@SuppressWarnings("NullAway.Init")
8081
private volatile Mono<ZMQ.Socket> socketMono;
8182

83+
@SuppressWarnings("NullAway.Init")
8284
private OutboundMessageMapper<byte[]> messageMapper;
8385

8486
private Consumer<ZMQ.Socket> socketConfigurer = (socket) -> {
8587
};
8688

8789
private Expression topicExpression = new SupplierExpression<>(() -> null);
8890

91+
@SuppressWarnings("NullAway.Init")
8992
private EvaluationContext evaluationContext;
9093

9194
private volatile boolean initialized;
9295

96+
@SuppressWarnings("NullAway.Init")
9397
private volatile Disposable socketMonoSubscriber;
9498

9599
private volatile boolean wrapTopic = true;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides classes for outbound channel adapters over ZeroMQ.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.zeromq.outbound;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides common classes for supporting ZeroMQ components.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.zeromq;

0 commit comments

Comments
 (0)