Skip to content

Commit 63eb82e

Browse files
piotrooofmbenhassine
authored andcommitted
Add JSpecify checks
Issue #1184 Signed-off-by: Piotr Olaszewski <[email protected]>
1 parent d396282 commit 63eb82e

File tree

184 files changed

+1846
-1047
lines changed

Some content is hidden

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

184 files changed

+1846
-1047
lines changed

.github/workflows/ci-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
cache: 'maven'
2121

2222
- name: Build with Maven
23-
run: ./mvnw --no-transfer-progress --batch-mode --update-snapshots verify
23+
run: ./mvnw --no-transfer-progress --batch-mode --update-snapshots verify -Pnullaway
2424

.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
<commons-io.version>2.20.0</commons-io.version>
5757
<slf4j.version>2.0.17</slf4j.version>
5858
<jakarta.validation-api.version>3.1.1</jakarta.validation-api.version>
59+
<errorprone.version>2.36.0</errorprone.version>
60+
<nullaway.version>0.12.7</nullaway.version>
61+
<jspecify.version>1.0.0</jspecify.version>
5962

6063
<!-- test dependencies -->
6164
<jimfs.version>1.3.1</jimfs.version>
@@ -228,6 +231,59 @@
228231
</plugins>
229232
</build>
230233

234+
<profiles>
235+
<profile>
236+
<id>nullaway</id>
237+
<build>
238+
<plugins>
239+
<plugin>
240+
<groupId>org.apache.maven.plugins</groupId>
241+
<artifactId>maven-compiler-plugin</artifactId>
242+
<configuration>
243+
<showWarnings>true</showWarnings>
244+
245+
</configuration>
246+
<executions>
247+
<execution>
248+
<id>default-compile</id>
249+
<phase>none</phase>
250+
</execution>
251+
<execution>
252+
<id>java-compile</id>
253+
<phase>compile</phase>
254+
<goals>
255+
<goal>compile</goal>
256+
</goals>
257+
<configuration>
258+
<annotationProcessorPaths>
259+
<path>
260+
<groupId>com.google.errorprone</groupId>
261+
<artifactId>error_prone_core</artifactId>
262+
<version>${errorprone.version}</version>
263+
</path>
264+
<path>
265+
<groupId>com.uber.nullaway</groupId>
266+
<artifactId>nullaway</artifactId>
267+
<version>${nullaway.version}</version>
268+
</path>
269+
</annotationProcessorPaths>
270+
<compilerArgs>
271+
<arg>-XDcompilePolicy=simple</arg>
272+
<arg>--should-stop=ifError=FLOW</arg>
273+
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR
274+
-XepOpt:NullAway:OnlyNullMarked=true
275+
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
276+
</arg>
277+
</compilerArgs>
278+
</configuration>
279+
</execution>
280+
</executions>
281+
</plugin>
282+
</plugins>
283+
</build>
284+
</profile>
285+
</profiles>
286+
231287
<repositories>
232288
<repository>
233289
<id>maven-central</id>

spring-shell-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
<version>${spring-boot.version}</version>
4848
<optional>true</optional>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.jspecify</groupId>
52+
<artifactId>jspecify</artifactId>
53+
<version>${jspecify.version}</version>
54+
</dependency>
5055

5156
<!-- Test dependencies -->
5257
<dependency>

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/CompleterAutoConfiguration.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import org.springframework.shell.CompletionProposal;
3232
import org.springframework.shell.Shell;
3333

34+
/**
35+
* @author Piotr Olaszewski
36+
*/
3437
@AutoConfiguration
3538
public class CompleterAutoConfiguration {
3639

@@ -39,15 +42,17 @@ public class CompleterAutoConfiguration {
3942

4043
@Bean
4144
public CompleterAdapter completer() {
42-
CompleterAdapter completerAdapter = new CompleterAdapter();
43-
completerAdapter.setShell(shell);
44-
return completerAdapter;
45+
return new CompleterAdapter(shell);
4546
}
4647

4748
public static class CompleterAdapter implements Completer {
4849

4950
private Shell shell;
5051

52+
public CompleterAdapter(Shell shell) {
53+
this.shell = shell;
54+
}
55+
5156
@Override
5257
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
5358
CompletingParsedLine cpl = (line instanceof CompletingParsedLine) ? ((CompletingParsedLine) line) : t -> t;

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/LineReaderAutoConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
import org.springframework.shell.config.UserConfigPathProvider;
4343
import org.springframework.util.StringUtils;
4444

45+
/**
46+
* @author Piotr Olaszewski
47+
*/
4548
@AutoConfiguration
4649
@EnableConfigurationProperties(SpringShellProperties.class)
4750
public class LineReaderAutoConfiguration {
@@ -59,7 +62,7 @@ public class LineReaderAutoConfiguration {
5962
private org.jline.reader.History jLineHistory;
6063

6164
@Value("${spring.application.name:spring-shell}.log")
62-
private String fallbackHistoryFileName;
65+
private String fallbackHistoryFileName = "spring-shell.log";
6366

6467
private SpringShellProperties springShellProperties;
6568
private UserConfigPathProvider userConfigPathProvider;

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/SpringShellProperties.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package org.springframework.shell.boot;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.boot.context.properties.ConfigurationProperties;
1920

2021
/**
2122
* Configuration properties for shell.
2223
*
2324
* @author Janne Valkealahti
25+
* @author Piotr Olaszewski
2426
*/
2527
@ConfigurationProperties(prefix = "spring.shell")
2628
public class SpringShellProperties {
@@ -118,36 +120,36 @@ public void setContext(Context context) {
118120

119121
public static class Config {
120122

121-
private String env;
122-
private String location;
123+
private @Nullable String env;
124+
private @Nullable String location;
123125

124-
public String getEnv() {
126+
public @Nullable String getEnv() {
125127
return env;
126128
}
127129

128-
public void setEnv(String env) {
130+
public void setEnv(@Nullable String env) {
129131
this.env = env;
130132
}
131133

132-
public String getLocation() {
134+
public @Nullable String getLocation() {
133135
return location;
134136
}
135137

136-
public void setLocation(String location) {
138+
public void setLocation(@Nullable String location) {
137139
this.location = location;
138140
}
139141
}
140142

141143
public static class History {
142144

143-
private String name;
145+
private @Nullable String name;
144146
private boolean enabled = true;
145147

146-
public String getName() {
148+
public @Nullable String getName() {
147149
return name;
148150
}
149151

150-
public void setName(String name) {
152+
public void setName(@Nullable String name) {
151153
this.name = name;
152154
}
153155

@@ -189,7 +191,7 @@ public void setEnabled(boolean enabled) {
189191
public static class Noninteractive {
190192

191193
private boolean enabled = true;
192-
private String primaryCommand;
194+
private @Nullable String primaryCommand;
193195

194196
public boolean isEnabled() {
195197
return enabled;
@@ -199,24 +201,24 @@ public void setEnabled(boolean enabled) {
199201
this.enabled = enabled;
200202
}
201203

202-
public String getPrimaryCommand() {
204+
public @Nullable String getPrimaryCommand() {
203205
return primaryCommand;
204206
}
205207

206-
public void setPrimaryCommand(String primaryCommand) {
208+
public void setPrimaryCommand(@Nullable String primaryCommand) {
207209
this.primaryCommand = primaryCommand;
208210
}
209211
}
210212

211213
public static class Theme {
212214

213-
private String name;
215+
private @Nullable String name;
214216

215-
public String getName() {
217+
public @Nullable String getName() {
216218
return name;
217219
}
218220

219-
public void setName(String name) {
221+
public void setName(@Nullable String name) {
220222
this.name = name;
221223
}
222224
}
@@ -334,7 +336,7 @@ public void setEnabled(boolean enabled) {
334336
public static class CompletionCommand {
335337

336338
private boolean enabled = true;
337-
private String rootCommand;
339+
private @Nullable String rootCommand;
338340

339341
public boolean isEnabled() {
340342
return enabled;
@@ -344,11 +346,11 @@ public void setEnabled(boolean enabled) {
344346
this.enabled = enabled;
345347
}
346348

347-
public String getRootCommand() {
349+
public @Nullable String getRootCommand() {
348350
return rootCommand;
349351
}
350352

351-
public void setRootCommand(String rootCommand) {
353+
public void setRootCommand(@Nullable String rootCommand) {
352354
this.rootCommand = rootCommand;
353355
}
354356
}
@@ -625,7 +627,7 @@ public void setClose(boolean close) {
625627
}
626628
}
627629

628-
public static enum OptionNamingCase {
630+
public enum OptionNamingCase {
629631
NOOP,
630632
CAMEL,
631633
SNAKE,

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/StandardCommandsAutoConfiguration.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
import org.springframework.shell.standard.commands.Stacktrace;
4242
import org.springframework.shell.standard.commands.Version;
4343
import org.springframework.shell.tui.style.TemplateExecutor;
44+
import org.springframework.util.Assert;
4445

4546
/**
4647
* Creates beans for standard commands.
4748
*
4849
* @author Eric Bottard
4950
* @author Mahmoud Ben Hassine
51+
* @author Piotr Olaszewski
5052
*/
5153
@AutoConfiguration
5254
@ConditionalOnClass({ Help.Command.class })
@@ -57,7 +59,9 @@ public class StandardCommandsAutoConfiguration {
5759
@ConditionalOnMissingBean(Help.Command.class)
5860
@ConditionalOnProperty(prefix = "spring.shell.command.help", value = "enabled", havingValue = "true", matchIfMissing = true)
5961
public Help help(SpringShellProperties properties, ObjectProvider<TemplateExecutor> templateExecutor) {
60-
Help help = new Help(templateExecutor.getIfAvailable());
62+
TemplateExecutor executor = templateExecutor.getIfAvailable();
63+
Assert.notNull(executor, "'executor' must not be null");
64+
Help help = new Help(executor);
6165
if (properties.getCommand().getHelp().getGroupingMode() == GroupingMode.FLAT) {
6266
help.setShowGroups(false);
6367
}
@@ -105,15 +109,19 @@ public History historyCommand(org.jline.reader.History jLineHistory) {
105109
@ConditionalOnMissingBean(Completion.Command.class)
106110
@Conditional(OnCompletionCommandCondition.class)
107111
public Completion completion(SpringShellProperties properties) {
108-
return new Completion(properties.getCommand().getCompletion().getRootCommand());
112+
String rootCommand = properties.getCommand().getCompletion().getRootCommand();
113+
Assert.hasText(rootCommand, "'rootCommand' must be specified");
114+
return new Completion(rootCommand);
109115
}
110116

111117
@Bean
112118
@ConditionalOnMissingBean(Version.Command.class)
113119
@ConditionalOnProperty(prefix = "spring.shell.command.version", value = "enabled", havingValue = "true", matchIfMissing = true)
114120
public Version version(SpringShellProperties properties, ObjectProvider<BuildProperties> buildProperties,
115121
ObjectProvider<GitProperties> gitProperties, ObjectProvider<TemplateExecutor> templateExecutor) {
116-
Version version = new Version(templateExecutor.getIfAvailable());
122+
TemplateExecutor executor = templateExecutor.getIfAvailable();
123+
Assert.notNull(executor, "'executor' must not be null");
124+
Version version = new Version(executor);
117125
VersionCommand versionProperties = properties.getCommand().getVersion();
118126
version.setTemplate(versionProperties.getTemplate());
119127
return version;

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/UserConfigAutoConfiguration.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
import java.nio.file.Paths;
2020
import java.util.function.Function;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.boot.autoconfigure.AutoConfiguration;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2425
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2526
import org.springframework.context.annotation.Bean;
2627
import org.springframework.shell.config.UserConfigPathProvider;
2728
import org.springframework.util.StringUtils;
2829

30+
/**
31+
* @author Piotr Olaszewski
32+
*/
2933
@AutoConfiguration
3034
@EnableConfigurationProperties(SpringShellProperties.class)
3135
public class UserConfigAutoConfiguration {
@@ -42,14 +46,15 @@ public UserConfigPathProvider userConfigPathProvider(SpringShellProperties sprin
4246

4347
static class LocationResolver {
4448

45-
private final static String XDG_CONFIG_HOME = "XDG_CONFIG_HOME";
46-
private final static String APP_DATA = "APP_DATA";
49+
private static final String XDG_CONFIG_HOME = "XDG_CONFIG_HOME";
50+
private static final String APP_DATA = "APP_DATA";
4751
private static final String USERCONFIG_PLACEHOLDER = "{userconfig}";
48-
private Function<String, Path> pathProvider = (path) -> Paths.get(path);
49-
private final String configDirEnv;
50-
private final String configDirLocation;
5152

52-
LocationResolver(String configDirEnv, String configDirLocation) {
53+
private final Function<String, Path> pathProvider = Paths::get;
54+
private final @Nullable String configDirEnv;
55+
private final @Nullable String configDirLocation;
56+
57+
LocationResolver(@Nullable String configDirEnv, @Nullable String configDirLocation) {
5358
this.configDirEnv = configDirEnv;
5459
this.configDirLocation = configDirLocation;
5560
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package org.springframework.shell.boot.condition;
3+
4+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)