Skip to content

Commit 4d76f20

Browse files
committed
Add nullability annotations to module/spring-boot-devtools
See gh-46587
1 parent b23a530 commit 4d76f20

File tree

57 files changed

+245
-104
lines changed

Some content is hidden

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

57 files changed

+245
-104
lines changed

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteUrlPropertyExtractor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.Collections;
2222
import java.util.Map;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
2527
import org.springframework.context.ApplicationListener;
2628
import org.springframework.core.Ordered;
@@ -59,7 +61,7 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
5961
environment.getPropertySources().addLast(propertySource);
6062
}
6163

62-
private String cleanRemoteUrl(String url) {
64+
private @Nullable String cleanRemoteUrl(@Nullable String url) {
6365
if (StringUtils.hasText(url) && url.endsWith("/")) {
6466
return url.substring(0, url.length() - 1);
6567
}

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/ConditionEvaluationDeltaLoggingListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ConditionEvaluationDeltaLoggingListener
4141

4242
private static final Log logger = LogFactory.getLog(ConditionEvaluationDeltaLoggingListener.class);
4343

44+
@SuppressWarnings("NullAway.Init")
4445
private volatile ApplicationContext context;
4546

4647
@Override

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import javax.sql.DataSource;
2626

2727
import org.apache.derby.jdbc.EmbeddedDriver;
28+
import org.jspecify.annotations.Nullable;
2829

2930
import org.springframework.beans.factory.DisposableBean;
3031
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
3132
import org.springframework.beans.factory.config.BeanDefinition;
33+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3234
import org.springframework.boot.autoconfigure.AutoConfiguration;
3335
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3436
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
@@ -50,6 +52,7 @@
5052
import org.springframework.core.type.AnnotatedTypeMetadata;
5153
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
5254
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
55+
import org.springframework.util.Assert;
5356

5457
/**
5558
* {@link EnableAutoConfiguration Auto-configuration} for DevTools-specific
@@ -136,13 +139,13 @@ private enum InMemoryDatabase {
136139
HSQLDB("jdbc:hsqldb:mem:", Set.of("org.hsqldb.jdbcDriver", "org.hsqldb.jdbc.JDBCDriver",
137140
"org.hsqldb.jdbc.pool.JDBCXADataSource"));
138141

139-
private final String urlPrefix;
142+
private final @Nullable String urlPrefix;
140143

141144
private final ShutdownHandler shutdownHandler;
142145

143146
private final Set<String> driverClassNames;
144147

145-
InMemoryDatabase(String urlPrefix, Set<String> driverClassNames) {
148+
InMemoryDatabase(@Nullable String urlPrefix, Set<String> driverClassNames) {
146149
this(urlPrefix, driverClassNames, (dataSource) -> {
147150
try (Connection connection = dataSource.getConnection()) {
148151
try (Statement statement = connection.createStatement()) {
@@ -152,7 +155,8 @@ private enum InMemoryDatabase {
152155
});
153156
}
154157

155-
InMemoryDatabase(String urlPrefix, Set<String> driverClassNames, ShutdownHandler shutdownHandler) {
158+
InMemoryDatabase(@Nullable String urlPrefix, Set<String> driverClassNames,
159+
ShutdownHandler shutdownHandler) {
156160
this.urlPrefix = urlPrefix;
157161
this.driverClassNames = driverClassNames;
158162
this.shutdownHandler = shutdownHandler;
@@ -189,11 +193,13 @@ public ConfigurationPhase getConfigurationPhase() {
189193
@Override
190194
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
191195
ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools DataSource Condition");
192-
String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class, true, false);
196+
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
197+
Assert.state(beanFactory != null, "'beanFactory' must not be null");
198+
String[] dataSourceBeanNames = beanFactory.getBeanNamesForType(DataSource.class, true, false);
193199
if (dataSourceBeanNames.length != 1) {
194200
return ConditionOutcome.noMatch(message.didNotFind("a single DataSource bean").atAll());
195201
}
196-
if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class, true, false).length != 1) {
202+
if (beanFactory.getBeanNamesForType(DataSourceProperties.class, true, false).length != 1) {
197203
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
198204
}
199205
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java

Lines changed: 8 additions & 6 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
import org.springframework.boot.context.properties.NestedConfigurationProperty;
2628
import org.springframework.util.StringUtils;
@@ -76,7 +78,7 @@ public static class Restart {
7678
/**
7779
* Additional patterns that should be excluded from triggering a full restart.
7880
*/
79-
private String additionalExclude;
81+
private @Nullable String additionalExclude;
8082

8183
/**
8284
* Amount of time to wait between polling for classpath changes.
@@ -94,7 +96,7 @@ public static class Restart {
9496
* a simple name (without any path) of a file that appears on your classpath. If
9597
* not specified, any classpath file change triggers the restart.
9698
*/
97-
private String triggerFile;
99+
private @Nullable String triggerFile;
98100

99101
/**
100102
* Additional paths to watch for changes.
@@ -133,11 +135,11 @@ public void setExclude(String exclude) {
133135
this.exclude = exclude;
134136
}
135137

136-
public String getAdditionalExclude() {
138+
public @Nullable String getAdditionalExclude() {
137139
return this.additionalExclude;
138140
}
139141

140-
public void setAdditionalExclude(String additionalExclude) {
142+
public void setAdditionalExclude(@Nullable String additionalExclude) {
141143
this.additionalExclude = additionalExclude;
142144
}
143145

@@ -157,11 +159,11 @@ public void setQuietPeriod(Duration quietPeriod) {
157159
this.quietPeriod = quietPeriod;
158160
}
159161

160-
public String getTriggerFile() {
162+
public @Nullable String getTriggerFile() {
161163
return this.triggerFile;
162164
}
163165

164-
public void setTriggerFile(String triggerFile) {
166+
public void setTriggerFile(@Nullable String triggerFile) {
165167
this.triggerFile = triggerFile;
166168
}
167169

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
import io.r2dbc.spi.Connection;
2020
import io.r2dbc.spi.ConnectionFactory;
21+
import org.jspecify.annotations.Nullable;
2122
import org.reactivestreams.Publisher;
2223
import reactor.core.publisher.Mono;
2324

2425
import org.springframework.beans.factory.DisposableBean;
2526
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2627
import org.springframework.beans.factory.config.BeanDefinition;
28+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2729
import org.springframework.boot.autoconfigure.AutoConfiguration;
2830
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2931
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
@@ -40,6 +42,7 @@
4042
import org.springframework.context.annotation.ConfigurationCondition;
4143
import org.springframework.core.type.AnnotatedTypeMetadata;
4244
import org.springframework.core.type.MethodMetadata;
45+
import org.springframework.util.Assert;
4346

4447
/**
4548
* {@link EnableAutoConfiguration Auto-configuration} for DevTools-specific R2DBC
@@ -99,7 +102,7 @@ private Publisher<Void> closeConnection(Connection connection) {
99102
return closeConnection(connection, null);
100103
}
101104

102-
private Publisher<Void> closeConnection(Connection connection, Throwable ex) {
105+
private Publisher<Void> closeConnection(Connection connection, @Nullable Throwable ex) {
103106
return connection.close();
104107
}
105108

@@ -115,7 +118,9 @@ public ConfigurationPhase getConfigurationPhase() {
115118
@Override
116119
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
117120
ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools ConnectionFactory Condition");
118-
String[] beanNames = context.getBeanFactory().getBeanNamesForType(ConnectionFactory.class, true, false);
121+
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
122+
Assert.state(beanFactory != null, "'beanFactory' must not be null");
123+
String[] beanNames = beanFactory.getBeanNamesForType(ConnectionFactory.class, true, false);
119124
if (beanNames.length != 1) {
120125
return ConditionOutcome.noMatch(message.didNotFind("a single ConnectionFactory bean").atAll());
121126
}

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
25+
import org.jspecify.annotations.Nullable;
2526

2627
import org.springframework.boot.autoconfigure.AutoConfiguration;
2728
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -49,6 +50,7 @@
4950
import org.springframework.context.event.GenericApplicationListener;
5051
import org.springframework.core.ResolvableType;
5152
import org.springframework.core.log.LogMessage;
53+
import org.springframework.util.Assert;
5254
import org.springframework.util.StringUtils;
5355

5456
/**
@@ -116,6 +118,7 @@ RestartingClassPathChangeChangedEventListener restartingClassPathChangedEventLis
116118
ClassPathFileSystemWatcher classPathFileSystemWatcher(FileSystemWatcherFactory fileSystemWatcherFactory,
117119
ClassPathRestartStrategy classPathRestartStrategy) {
118120
URL[] urls = Restarter.getInstance().getInitialUrls();
121+
Assert.state(urls != null, "'urls' must not be null");
119122
ClassPathFileSystemWatcher watcher = new ClassPathFileSystemWatcher(fileSystemWatcherFactory,
120123
classPathRestartStrategy, urls);
121124
watcher.setStopWatcherOnRestart(true);
@@ -176,7 +179,7 @@ public boolean supportsEventType(ResolvableType eventType) {
176179
}
177180

178181
@Override
179-
public boolean supportsSourceType(Class<?> sourceType) {
182+
public boolean supportsSourceType(@Nullable Class<?> sourceType) {
180183
return true;
181184
}
182185

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
2122

2223
import org.springframework.beans.factory.InitializingBean;
2324
import org.springframework.boot.devtools.livereload.LiveReloadServer;
@@ -34,13 +35,13 @@ public class OptionalLiveReloadServer implements InitializingBean {
3435

3536
private static final Log logger = LogFactory.getLog(OptionalLiveReloadServer.class);
3637

37-
private LiveReloadServer server;
38+
private @Nullable LiveReloadServer server;
3839

3940
/**
4041
* Create a new {@link OptionalLiveReloadServer} instance.
4142
* @param server the server to manage or {@code null}
4243
*/
43-
public OptionalLiveReloadServer(LiveReloadServer server) {
44+
public OptionalLiveReloadServer(@Nullable LiveReloadServer server) {
4445
this.server = server;
4546
}
4647

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.springframework.context.annotation.Import;
4949
import org.springframework.core.log.LogMessage;
5050
import org.springframework.http.server.ServerHttpRequest;
51+
import org.springframework.util.Assert;
5152

5253
/**
5354
* {@link EnableAutoConfiguration Auto-configuration} for remote development support.
@@ -78,7 +79,9 @@ public final class RemoteDevToolsAutoConfiguration {
7879
@ConditionalOnMissingBean
7980
AccessManager remoteDevToolsAccessManager() {
8081
RemoteDevToolsProperties remoteProperties = this.properties.getRemote();
81-
return new HttpHeaderAccessManager(remoteProperties.getSecretHeaderName(), remoteProperties.getSecret());
82+
String secret = remoteProperties.getSecret();
83+
Assert.state(secret != null, "'secret' must not be null");
84+
return new HttpHeaderAccessManager(remoteProperties.getSecretHeaderName(), secret);
8285
}
8386

8487
@Bean

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsProperties.java

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

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

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Configuration properties for remote Spring Boot applications.
2123
*
@@ -39,7 +41,7 @@ public class RemoteDevToolsProperties {
3941
* A shared secret required to establish a connection (required to enable remote
4042
* support).
4143
*/
42-
private String secret;
44+
private @Nullable String secret;
4345

4446
/**
4547
* HTTP header used to transfer the shared secret.
@@ -58,11 +60,11 @@ public void setContextPath(String contextPath) {
5860
this.contextPath = contextPath;
5961
}
6062

61-
public String getSecret() {
63+
public @Nullable String getSecret() {
6264
return this.secret;
6365
}
6466

65-
public void setSecret(String secret) {
67+
public void setSecret(@Nullable String secret) {
6668
this.secret = secret;
6769
}
6870

@@ -104,26 +106,26 @@ public static class Proxy {
104106
/**
105107
* The host of the proxy to use to connect to the remote application.
106108
*/
107-
private String host;
109+
private @Nullable String host;
108110

109111
/**
110112
* The port of the proxy to use to connect to the remote application.
111113
*/
112-
private Integer port;
114+
private @Nullable Integer port;
113115

114-
public String getHost() {
116+
public @Nullable String getHost() {
115117
return this.host;
116118
}
117119

118-
public void setHost(String host) {
120+
public void setHost(@Nullable String host) {
119121
this.host = host;
120122
}
121123

122-
public Integer getPort() {
124+
public @Nullable Integer getPort() {
123125
return this.port;
124126
}
125127

126-
public void setPort(Integer port) {
128+
public void setPort(@Nullable Integer port) {
127129
this.port = port;
128130
}
129131

module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/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 {@code spring-boot-devtools}.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.devtools.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)