Skip to content

Commit 8d598f5

Browse files
committed
Add nullability annotations to cli/spring-boot-cli
See gh-46587
1 parent 924910f commit 8d598f5

29 files changed

+186
-98
lines changed

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/AbstractCommand.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.cli.command.options.OptionHelp;
2325

2426
/**
@@ -55,12 +57,12 @@ public String getDescription() {
5557
}
5658

5759
@Override
58-
public String getUsageHelp() {
60+
public @Nullable String getUsageHelp() {
5961
return null;
6062
}
6163

6264
@Override
63-
public String getHelp() {
65+
public @Nullable String getHelp() {
6466
return null;
6567
}
6668

@@ -70,7 +72,7 @@ public Collection<OptionHelp> getOptionsHelp() {
7072
}
7173

7274
@Override
73-
public Collection<HelpExample> getExamples() {
75+
public @Nullable Collection<HelpExample> getExamples() {
7476
return null;
7577
}
7678

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/Command.java

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

1919
import java.util.Collection;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.cli.command.options.OptionHelp;
2224
import org.springframework.boot.cli.command.status.ExitStatus;
2325

@@ -50,14 +52,14 @@ public interface Command {
5052
* the command in this string.
5153
* @return the command's usage help
5254
*/
53-
String getUsageHelp();
55+
@Nullable String getUsageHelp();
5456

5557
/**
5658
* Gets full help text for the command, e.g. a longer description and one line per
5759
* option.
5860
* @return the command's help text
5961
*/
60-
String getHelp();
62+
@Nullable String getHelp();
6163

6264
/**
6365
* Returns help for each supported option.
@@ -69,7 +71,7 @@ public interface Command {
6971
* Return some examples for the command.
7072
* @return the command's examples
7173
*/
72-
Collection<HelpExample> getExamples();
74+
@Nullable Collection<HelpExample> getExamples();
7375

7476
/**
7577
* Run the command.

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandException.java

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

24+
import org.jspecify.annotations.Nullable;
25+
2426
/**
2527
* Runtime exception wrapper that defines additional {@link Option}s that are understood
2628
* by the {@link CommandRunner}.
@@ -73,7 +75,7 @@ public CommandException(Throwable cause, Option... options) {
7375
this.options = asEnumSet(options);
7476
}
7577

76-
private EnumSet<Option> asEnumSet(Option[] options) {
78+
private EnumSet<Option> asEnumSet(Option @Nullable [] options) {
7779
if (options == null || options.length == 0) {
7880
return EnumSet.noneOf(Option.class);
7981
}

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27+
import org.jspecify.annotations.Nullable;
28+
2729
import org.springframework.boot.cli.command.status.ExitStatus;
2830
import org.springframework.boot.cli.util.Log;
2931
import org.springframework.util.Assert;
@@ -54,7 +56,7 @@ public class CommandRunner implements Iterable<Command> {
5456
* Create a new {@link CommandRunner} instance.
5557
* @param name the name of the runner or {@code null}
5658
*/
57-
public CommandRunner(String name) {
59+
public CommandRunner(@Nullable String name) {
5860
this.name = StringUtils.hasLength(name) ? name + " " : "";
5961
}
6062

@@ -146,7 +148,7 @@ protected final List<Command> getCommands() {
146148
* @param name the name of the command
147149
* @return the command or {@code null} if not found
148150
*/
149-
public Command findCommand(String name) {
151+
public @Nullable Command findCommand(String name) {
150152
for (Command candidate : this.commands) {
151153
String candidateName = candidate.getName();
152154
if (candidateName.equals(name) || (isOptionCommand(candidate) && ("--" + candidateName).equals(name))) {
@@ -258,7 +260,7 @@ private int handleError(boolean debug, Exception ex) {
258260
return 1;
259261
}
260262

261-
protected boolean errorMessage(String message) {
263+
protected boolean errorMessage(@Nullable String message) {
262264
Log.error((message != null) ? message : "Unexpected error");
263265
return message != null;
264266
}

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/HelpCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Set;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
import org.springframework.boot.cli.command.AbstractCommand;
2628
import org.springframework.boot.cli.command.Command;
2729
import org.springframework.boot.cli.command.CommandRunner;
@@ -53,7 +55,7 @@ public String getUsageHelp() {
5355
}
5456

5557
@Override
56-
public String getHelp() {
58+
public @Nullable String getHelp() {
5759
return null;
5860
}
5961

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/core/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Core CLI commands.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.cli.command.core;
22+
23+
import org.jspecify.annotations.NullMarked;

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Collection<HelpExample> getExamples() {
7979

8080
private static final class EncodePasswordOptionHandler extends OptionHandler {
8181

82+
@SuppressWarnings("NullAway.Init")
8283
private OptionSpec<String> algorithm;
8384

8485
@Override

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/encodepassword/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* CLI command for password encoding.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.cli.command.encodepassword;
22+
23+
import org.jspecify.annotations.NullMarked;

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/Dependency.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,36 @@
1616

1717
package org.springframework.boot.cli.command.init;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Provide some basic information about a dependency.
2123
*
2224
* @author Stephane Nicoll
2325
*/
2426
final class Dependency {
2527

26-
private final String id;
28+
private final @Nullable String id;
2729

28-
private final String name;
30+
private final @Nullable String name;
2931

30-
private final String description;
32+
private final @Nullable String description;
3133

32-
Dependency(String id, String name, String description) {
34+
Dependency(@Nullable String id, @Nullable String name, @Nullable String description) {
3335
this.id = id;
3436
this.name = name;
3537
this.description = description;
3638
}
3739

38-
String getId() {
40+
@Nullable String getId() {
3941
return this.id;
4042
}
4143

42-
String getName() {
44+
@Nullable String getName() {
4345
return this.name;
4446
}
4547

46-
String getDescription() {
48+
@Nullable String getDescription() {
4749
return this.description;
4850
}
4951

cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,40 +94,58 @@ static class InitOptionHandler extends OptionHandler {
9494

9595
private final ProjectGenerator projectGenerator;
9696

97+
@SuppressWarnings("NullAway.Init")
9798
private OptionSpec<String> target;
9899

100+
@SuppressWarnings("NullAway.Init")
99101
private OptionSpec<Void> listCapabilities;
100102

103+
@SuppressWarnings("NullAway.Init")
101104
private OptionSpec<String> groupId;
102105

106+
@SuppressWarnings("NullAway.Init")
103107
private OptionSpec<String> artifactId;
104108

109+
@SuppressWarnings("NullAway.Init")
105110
private OptionSpec<String> version;
106111

112+
@SuppressWarnings("NullAway.Init")
107113
private OptionSpec<String> name;
108114

115+
@SuppressWarnings("NullAway.Init")
109116
private OptionSpec<String> description;
110117

118+
@SuppressWarnings("NullAway.Init")
111119
private OptionSpec<String> packageName;
112120

121+
@SuppressWarnings("NullAway.Init")
113122
private OptionSpec<String> type;
114123

124+
@SuppressWarnings("NullAway.Init")
115125
private OptionSpec<String> packaging;
116126

127+
@SuppressWarnings("NullAway.Init")
117128
private OptionSpec<String> build;
118129

130+
@SuppressWarnings("NullAway.Init")
119131
private OptionSpec<String> format;
120132

133+
@SuppressWarnings("NullAway.Init")
121134
private OptionSpec<String> javaVersion;
122135

136+
@SuppressWarnings("NullAway.Init")
123137
private OptionSpec<String> language;
124138

139+
@SuppressWarnings("NullAway.Init")
125140
private OptionSpec<String> bootVersion;
126141

142+
@SuppressWarnings("NullAway.Init")
127143
private OptionSpec<String> dependencies;
128144

145+
@SuppressWarnings("NullAway.Init")
129146
private OptionSpec<Void> extract;
130147

148+
@SuppressWarnings("NullAway.Init")
131149
private OptionSpec<Void> force;
132150

133151
InitOptionHandler(InitializrService initializrService) {

0 commit comments

Comments
 (0)