Skip to content

Commit ee7a9da

Browse files
committed
Fix warnings
- Fix some potential NPE cases. - Fix warnings for missing @nullable
1 parent 83fb5f7 commit ee7a9da

File tree

11 files changed

+48
-28
lines changed

11 files changed

+48
-28
lines changed

spring-shell-core/src/main/java/org/springframework/shell/component/ConfirmationInput.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ public ConfirmationInputContext getThisContext(ComponentContext<?> context) {
7272
}
7373
currentContext = ConfirmationInputContext.of(defaultValue);
7474
currentContext.setName(getName());
75-
context.stream().forEach(e -> {
76-
currentContext.put(e.getKey(), e.getValue());
77-
});
75+
if (context != null) {
76+
context.stream().forEach(e -> {
77+
currentContext.put(e.getKey(), e.getValue());
78+
});
79+
}
7880
return currentContext;
7981
}
8082

spring-shell-core/src/main/java/org/springframework/shell/component/MultiItemSelector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public MultiItemSelectorContext<T, I> getThisContext(ComponentContext<?> context
6363
if (currentContext.getItems() == null) {
6464
currentContext.setItems(getItems());
6565
}
66-
context.stream().forEach(e -> {
67-
currentContext.put(e.getKey(), e.getValue());
68-
});
66+
if (context != null) {
67+
context.stream().forEach(e -> {
68+
currentContext.put(e.getKey(), e.getValue());
69+
});
70+
}
6971
return currentContext;
7072
}
7173

spring-shell-core/src/main/java/org/springframework/shell/component/PathInput.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ public PathInputContext getThisContext(ComponentContext<?> context) {
6969
}
7070
currentContext = PathInputContext.empty();
7171
currentContext.setName(getName());
72-
context.stream().forEach(e -> {
73-
currentContext.put(e.getKey(), e.getValue());
74-
});
72+
if (context != null) {
73+
context.stream().forEach(e -> {
74+
currentContext.put(e.getKey(), e.getValue());
75+
});
76+
}
7577
return currentContext;
7678
}
7779

spring-shell-core/src/main/java/org/springframework/shell/component/PathSearch.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ public PathSearchContext getThisContext(ComponentContext<?> context) {
124124
currentContext.setTerminalWidth(getTerminal().getWidth());
125125
currentContext.setPathSearchConfig(this.config);
126126
currentContext.setMessage("Type '<path> <pattern>' to search", MessageLevel.INFO);
127-
context.stream().forEach(e -> {
128-
currentContext.put(e.getKey(), e.getValue());
129-
});
127+
if (context != null) {
128+
context.stream().forEach(e -> {
129+
currentContext.put(e.getKey(), e.getValue());
130+
});
131+
}
130132
return currentContext;
131133
}
132134

spring-shell-core/src/main/java/org/springframework/shell/component/SingleItemSelector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public SingleItemSelectorContext<T, I> getThisContext(ComponentContext<?> contex
6363
if (currentContext.getItems() == null) {
6464
currentContext.setItems(getItems());
6565
}
66-
context.stream().forEach(e -> {
67-
currentContext.put(e.getKey(), e.getValue());
68-
});
66+
if (context != null) {
67+
context.stream().forEach(e -> {
68+
currentContext.put(e.getKey(), e.getValue());
69+
});
70+
}
6971
return currentContext;
7072
}
7173

spring-shell-core/src/main/java/org/springframework/shell/component/StringInput.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ public StringInputContext getThisContext(ComponentContext<?> context) {
7777
}
7878
currentContext = StringInputContext.of(defaultValue, maskCharacter);
7979
currentContext.setName(getName());
80-
context.stream().forEach(e -> {
81-
currentContext.put(e.getKey(), e.getValue());
82-
});
80+
if (context != null) {
81+
context.stream().forEach(e -> {
82+
currentContext.put(e.getKey(), e.getValue());
83+
});
84+
}
8385
return currentContext;
8486
}
8587

spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,24 @@ else if (!isEscapeChar(line, i)) {
125125
}
126126
}
127127

128-
if (current.length() > 0 || cursor == line.length()) {
128+
if (current.length() > 0 || (line != null && cursor == line.length())) {
129129
words.add(current.toString());
130130
}
131131

132-
if (cursor == line.length()) {
132+
if (line != null && cursor == line.length()) {
133133
wordIndex = words.size() - 1;
134134
wordCursor = words.get(words.size() - 1).length();
135135
}
136136

137-
if (eofOnEscapedNewLine && isEscapeChar(line, line.length() - 1)) {
137+
if (eofOnEscapedNewLine && (line != null && isEscapeChar(line, line.length() - 1))) {
138138
throw new EOFError(-1, -1, "Escaped new line", "newline");
139139
}
140140
if (eofOnUnclosedQuote && quoteStart >= 0 && context != ParseContext.COMPLETE) {
141-
throw new EOFError(-1, -1, "Missing closing quote", line.charAt(quoteStart) == '\'' ? "quote" : "dquote");
141+
throw new EOFError(-1, -1, "Missing closing quote",
142+
(line != null && line.charAt(quoteStart) == '\'') ? "quote" : "dquote");
142143
}
143144

144-
String openingQuote = quoteStart >= 0 ? line.substring(quoteStart, quoteStart + 1) : null;
145+
String openingQuote = (quoteStart >= 0 && line != null) ? line.substring(quoteStart, quoteStart + 1) : null;
145146
return wrap(new ExtendedArgumentList(line, words, wordIndex, wordCursor, cursor, openingQuote));
146147
}
147148

spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/Stacktrace.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ public Stacktrace(ObjectProvider<ThrowableResultHandler> throwableResultHandler)
5454
value = "Display the full stacktrace of the last error.",
5555
interactionMode = InteractionMode.INTERACTIVE)
5656
public void stacktrace() {
57-
if (throwableResultHandler.getIfAvailable().getLastError() != null) {
58-
throwableResultHandler.getIfAvailable().getLastError().printStackTrace(getTerminal().writer());
57+
ThrowableResultHandler handler = throwableResultHandler.getIfAvailable();
58+
if (handler != null) {
59+
if (handler.getLastError() != null) {
60+
handler.getLastError().printStackTrace(getTerminal().writer());
61+
}
5962
}
6063
}
6164
}

spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsModelsRuntimeHints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.aot.hint.RuntimeHints;
2424
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2525
import org.springframework.aot.hint.TypeReference;
26+
import org.springframework.lang.Nullable;
2627

2728
/**
2829
* {@link RuntimeHintsRegistrar} for Shell Standard Commands temlate model classes.
@@ -32,7 +33,7 @@
3233
class StandardCommandsModelsRuntimeHints implements RuntimeHintsRegistrar {
3334

3435
@Override
35-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
36+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3637
ReflectionHints reflection = hints.reflection();
3738
registerForDeclaredMethodsInvocation(reflection, CommandAvailabilityInfoModel.class, CommandInfoModel.class,
3839
CommandParameterInfoModel.class, GroupCommandInfoModel.class, GroupsInfoModel.class);

spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsResourcesRuntimeHints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.springframework.aot.hint.RuntimeHints;
1919
import org.springframework.aot.hint.RuntimeHintsRegistrar;
20+
import org.springframework.lang.Nullable;
2021

2122
/**
2223
* {@link RuntimeHintsRegistrar} for Shell Standard Commands resources.
@@ -26,7 +27,7 @@
2627
class StandardCommandsResourcesRuntimeHints implements RuntimeHintsRegistrar {
2728

2829
@Override
29-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
30+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3031
hints.resources()
3132
.registerPattern("template/*.st")
3233
.registerPattern("template/*.stg");

0 commit comments

Comments
 (0)