Skip to content

Commit 50c9615

Browse files
committed
Add nullability annotations to module/spring-boot-integration
See gh-46587
1 parent 12cb825 commit 50c9615

File tree

9 files changed

+70
-35
lines changed

9 files changed

+70
-35
lines changed

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfiguration.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.sql.DataSource;
2323

2424
import io.rsocket.transport.netty.server.TcpServerTransport;
25+
import org.jspecify.annotations.Nullable;
2526

2627
import org.springframework.beans.factory.ObjectProvider;
2728
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -40,6 +41,7 @@
4041
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4142
import org.springframework.boot.context.properties.PropertyMapper;
4243
import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException;
44+
import org.springframework.boot.integration.autoconfigure.IntegrationProperties.Poller;
4345
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
4446
import org.springframework.boot.sql.autoconfigure.init.OnDatabaseInitializationCondition;
4547
import org.springframework.boot.task.SimpleAsyncTaskSchedulerBuilder;
@@ -144,12 +146,18 @@ PollerMetadata defaultPollerMetadata(IntegrationProperties integrationProperties
144146
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
145147
map.from(poller::getMaxMessagesPerPoll).to(pollerMetadata::setMaxMessagesPerPoll);
146148
map.from(poller::getReceiveTimeout).as(Duration::toMillis).to(pollerMetadata::setReceiveTimeout);
147-
map.from(poller).as(this::asTrigger).to(pollerMetadata::setTrigger);
149+
setTrigger(map, poller, pollerMetadata);
148150
customizers.orderedStream().forEach((customizer) -> customizer.customize(pollerMetadata));
149151
return pollerMetadata;
150152
}
151153

152-
private Trigger asTrigger(IntegrationProperties.Poller poller) {
154+
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct
155+
// nullability
156+
private void setTrigger(PropertyMapper map, Poller poller, PollerMetadata pollerMetadata) {
157+
map.from(poller).as(this::asTrigger).to(pollerMetadata::setTrigger);
158+
}
159+
160+
private @Nullable Trigger asTrigger(IntegrationProperties.Poller poller) {
153161
if (StringUtils.hasText(poller.getCron())) {
154162
return new CronTrigger(poller.getCron());
155163
}
@@ -162,7 +170,7 @@ private Trigger asTrigger(IntegrationProperties.Poller poller) {
162170
return null;
163171
}
164172

165-
private Trigger createPeriodicTrigger(Duration period, Duration initialDelay, boolean fixedRate) {
173+
private Trigger createPeriodicTrigger(Duration period, @Nullable Duration initialDelay, boolean fixedRate) {
166174
PeriodicTrigger trigger = new PeriodicTrigger(period);
167175
if (initialDelay != null) {
168176
trigger.setInitialDelay(initialDelay);
@@ -348,11 +356,17 @@ protected static class IntegrationRSocketClientConfiguration {
348356
@Conditional(RemoteRSocketServerAddressConfigured.class)
349357
ClientRSocketConnector clientRSocketConnector(IntegrationProperties integrationProperties,
350358
RSocketStrategies rSocketStrategies) {
351-
352359
IntegrationProperties.RSocket.Client client = integrationProperties.getRsocket().getClient();
353-
ClientRSocketConnector clientRSocketConnector = (client.getUri() != null)
354-
? new ClientRSocketConnector(client.getUri())
355-
: new ClientRSocketConnector(client.getHost(), client.getPort());
360+
ClientRSocketConnector clientRSocketConnector;
361+
if (client.getUri() != null) {
362+
clientRSocketConnector = new ClientRSocketConnector(client.getUri());
363+
}
364+
else if (client.getHost() != null && client.getPort() != null) {
365+
clientRSocketConnector = new ClientRSocketConnector(client.getHost(), client.getPort());
366+
}
367+
else {
368+
throw new IllegalStateException("Neither uri nor host and port is set");
369+
}
356370
clientRSocketConnector.setRSocketStrategies(rSocketStrategies);
357371
return clientRSocketConnector;
358372
}

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationAutoConfigurationScanRegistrar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
class IntegrationAutoConfigurationScanRegistrar extends IntegrationComponentScanRegistrar implements BeanFactoryAware {
4040

41+
@SuppressWarnings("NullAway.Init")
4142
private BeanFactory beanFactory;
4243

4344
@Override

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationJdbcProperties.java

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

1717
package org.springframework.boot.integration.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.context.properties.ConfigurationProperties;
2022
import org.springframework.boot.sql.init.DatabaseInitializationMode;
2123

@@ -42,7 +44,7 @@ public class IntegrationJdbcProperties {
4244
* Platform to use in initialization scripts if the @@platform@@ placeholder is used.
4345
* Auto-detected by default.
4446
*/
45-
private String platform;
47+
private @Nullable String platform;
4648

4749
/**
4850
* Database schema initialization mode.
@@ -57,11 +59,11 @@ public void setSchema(String schema) {
5759
this.schema = schema;
5860
}
5961

60-
public String getPlatform() {
62+
public @Nullable String getPlatform() {
6163
return this.platform;
6264
}
6365

64-
public void setPlatform(String platform) {
66+
public void setPlatform(@Nullable String platform) {
6567
this.platform = platform;
6668
}
6769

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationProperties.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.context.properties.ConfigurationProperties;
2527

2628
/**
@@ -224,39 +226,39 @@ public static class Client {
224226
/**
225227
* TCP RSocket server host to connect to.
226228
*/
227-
private String host;
229+
private @Nullable String host;
228230

229231
/**
230232
* TCP RSocket server port to connect to.
231233
*/
232-
private Integer port;
234+
private @Nullable Integer port;
233235

234236
/**
235237
* WebSocket RSocket server uri to connect to.
236238
*/
237-
private URI uri;
239+
private @Nullable URI uri;
238240

239-
public void setHost(String host) {
241+
public void setHost(@Nullable String host) {
240242
this.host = host;
241243
}
242244

243-
public String getHost() {
245+
public @Nullable String getHost() {
244246
return this.host;
245247
}
246248

247-
public void setPort(Integer port) {
249+
public void setPort(@Nullable Integer port) {
248250
this.port = port;
249251
}
250252

251-
public Integer getPort() {
253+
public @Nullable Integer getPort() {
252254
return this.port;
253255
}
254256

255-
public void setUri(URI uri) {
257+
public void setUri(@Nullable URI uri) {
256258
this.uri = uri;
257259
}
258260

259-
public URI getUri() {
261+
public @Nullable URI getUri() {
260262
return this.uri;
261263
}
262264

@@ -296,24 +298,24 @@ public static class Poller {
296298
/**
297299
* Polling delay period. Mutually exclusive with 'cron' and 'fixedRate'.
298300
*/
299-
private Duration fixedDelay;
301+
private @Nullable Duration fixedDelay;
300302

301303
/**
302304
* Polling rate period. Mutually exclusive with 'fixedDelay' and 'cron'.
303305
*/
304-
private Duration fixedRate;
306+
private @Nullable Duration fixedRate;
305307

306308
/**
307309
* Polling initial delay. Applied for 'fixedDelay' and 'fixedRate'; ignored for
308310
* 'cron'.
309311
*/
310-
private Duration initialDelay;
312+
private @Nullable Duration initialDelay;
311313

312314
/**
313315
* Cron expression for polling. Mutually exclusive with 'fixedDelay' and
314316
* 'fixedRate'.
315317
*/
316-
private String cron;
318+
private @Nullable String cron;
317319

318320
public int getMaxMessagesPerPoll() {
319321
return this.maxMessagesPerPoll;
@@ -331,35 +333,35 @@ public void setReceiveTimeout(Duration receiveTimeout) {
331333
this.receiveTimeout = receiveTimeout;
332334
}
333335

334-
public Duration getFixedDelay() {
336+
public @Nullable Duration getFixedDelay() {
335337
return this.fixedDelay;
336338
}
337339

338-
public void setFixedDelay(Duration fixedDelay) {
340+
public void setFixedDelay(@Nullable Duration fixedDelay) {
339341
this.fixedDelay = fixedDelay;
340342
}
341343

342-
public Duration getFixedRate() {
344+
public @Nullable Duration getFixedRate() {
343345
return this.fixedRate;
344346
}
345347

346-
public void setFixedRate(Duration fixedRate) {
348+
public void setFixedRate(@Nullable Duration fixedRate) {
347349
this.fixedRate = fixedRate;
348350
}
349351

350-
public Duration getInitialDelay() {
352+
public @Nullable Duration getInitialDelay() {
351353
return this.initialDelay;
352354
}
353355

354-
public void setInitialDelay(Duration initialDelay) {
356+
public void setInitialDelay(@Nullable Duration initialDelay) {
355357
this.initialDelay = initialDelay;
356358
}
357359

358-
public String getCron() {
360+
public @Nullable String getCron() {
359361
return this.cron;
360362
}
361363

362-
public void setCron(String cron) {
364+
public void setCron(@Nullable String cron) {
363365
this.cron = cron;
364366
}
365367

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/IntegrationPropertiesEnvironmentPostProcessor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.SpringApplication;
2527
import org.springframework.boot.env.EnvironmentPostProcessor;
2628
import org.springframework.boot.env.OriginTrackedMapPropertySource;
@@ -101,13 +103,15 @@ private static final class IntegrationPropertiesPropertySource extends PropertyS
101103
}
102104

103105
@Override
104-
public Object getProperty(String name) {
105-
return this.delegate.getProperty(KEYS_MAPPING.get(name));
106+
public @Nullable Object getProperty(String name) {
107+
String mapped = KEYS_MAPPING.get(name);
108+
return (mapped != null) ? this.delegate.getProperty(mapped) : null;
106109
}
107110

108111
@Override
109-
public Origin getOrigin(String key) {
110-
return this.delegate.getOrigin(KEYS_MAPPING.get(key));
112+
public @Nullable Origin getOrigin(String key) {
113+
String mapped = KEYS_MAPPING.get(key);
114+
return (mapped != null) ? this.delegate.getOrigin(mapped) : null;
111115
}
112116

113117
}

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring Integration endpoint.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.integration.autoconfigure.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/metrics/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring Integration metrics.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.integration.autoconfigure.metrics;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring Integration.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.integration.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-integration/src/main/java/org/springframework/boot/integration/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator endpoint for Spring Integration.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.integration.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)