Fix warnings
- Fix some potential NPE cases. - Fix warnings for missing @Nullable
This commit is contained in:
@@ -72,9 +72,11 @@ public class ConfirmationInput extends AbstractTextComponent<Boolean, Confirmati
|
||||
}
|
||||
currentContext = ConfirmationInputContext.of(defaultValue);
|
||||
currentContext.setName(getName());
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,11 @@ public class MultiItemSelector<T, I extends Nameable & Matchable & Enableable &
|
||||
if (currentContext.getItems() == null) {
|
||||
currentContext.setItems(getItems());
|
||||
}
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,9 +69,11 @@ public class PathInput extends AbstractTextComponent<Path, PathInputContext> {
|
||||
}
|
||||
currentContext = PathInputContext.empty();
|
||||
currentContext.setName(getName());
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,11 @@ public class PathSearch extends AbstractTextComponent<Path, PathSearchContext> {
|
||||
currentContext.setTerminalWidth(getTerminal().getWidth());
|
||||
currentContext.setPathSearchConfig(this.config);
|
||||
currentContext.setMessage("Type '<path> <pattern>' to search", MessageLevel.INFO);
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,11 @@ public class SingleItemSelector<T, I extends Nameable & Matchable & Enableable &
|
||||
if (currentContext.getItems() == null) {
|
||||
currentContext.setItems(getItems());
|
||||
}
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,11 @@ public class StringInput extends AbstractTextComponent<String, StringInputContex
|
||||
}
|
||||
currentContext = StringInputContext.of(defaultValue, maskCharacter);
|
||||
currentContext.setName(getName());
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
if (context != null) {
|
||||
context.stream().forEach(e -> {
|
||||
currentContext.put(e.getKey(), e.getValue());
|
||||
});
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,23 +125,24 @@ public class ExtendedDefaultParser implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
if (current.length() > 0 || cursor == line.length()) {
|
||||
if (current.length() > 0 || (line != null && cursor == line.length())) {
|
||||
words.add(current.toString());
|
||||
}
|
||||
|
||||
if (cursor == line.length()) {
|
||||
if (line != null && cursor == line.length()) {
|
||||
wordIndex = words.size() - 1;
|
||||
wordCursor = words.get(words.size() - 1).length();
|
||||
}
|
||||
|
||||
if (eofOnEscapedNewLine && isEscapeChar(line, line.length() - 1)) {
|
||||
if (eofOnEscapedNewLine && (line != null && isEscapeChar(line, line.length() - 1))) {
|
||||
throw new EOFError(-1, -1, "Escaped new line", "newline");
|
||||
}
|
||||
if (eofOnUnclosedQuote && quoteStart >= 0 && context != ParseContext.COMPLETE) {
|
||||
throw new EOFError(-1, -1, "Missing closing quote", line.charAt(quoteStart) == '\'' ? "quote" : "dquote");
|
||||
throw new EOFError(-1, -1, "Missing closing quote",
|
||||
(line != null && line.charAt(quoteStart) == '\'') ? "quote" : "dquote");
|
||||
}
|
||||
|
||||
String openingQuote = quoteStart >= 0 ? line.substring(quoteStart, quoteStart + 1) : null;
|
||||
String openingQuote = (quoteStart >= 0 && line != null) ? line.substring(quoteStart, quoteStart + 1) : null;
|
||||
return wrap(new ExtendedArgumentList(line, words, wordIndex, wordCursor, cursor, openingQuote));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,11 @@ public class Stacktrace extends AbstractShellComponent {
|
||||
value = "Display the full stacktrace of the last error.",
|
||||
interactionMode = InteractionMode.INTERACTIVE)
|
||||
public void stacktrace() {
|
||||
if (throwableResultHandler.getIfAvailable().getLastError() != null) {
|
||||
throwableResultHandler.getIfAvailable().getLastError().printStackTrace(getTerminal().writer());
|
||||
ThrowableResultHandler handler = throwableResultHandler.getIfAvailable();
|
||||
if (handler != null) {
|
||||
if (handler.getLastError() != null) {
|
||||
handler.getLastError().printStackTrace(getTerminal().writer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.aot.hint.ReflectionHints;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} for Shell Standard Commands temlate model classes.
|
||||
@@ -32,7 +33,7 @@ import org.springframework.aot.hint.TypeReference;
|
||||
class StandardCommandsModelsRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
ReflectionHints reflection = hints.reflection();
|
||||
registerForDeclaredMethodsInvocation(reflection, CommandAvailabilityInfoModel.class, CommandInfoModel.class,
|
||||
CommandParameterInfoModel.class, GroupCommandInfoModel.class, GroupsInfoModel.class);
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.shell.standard.commands;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} for Shell Standard Commands resources.
|
||||
@@ -26,7 +27,7 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
class StandardCommandsResourcesRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
hints.resources()
|
||||
.registerPattern("template/*.st")
|
||||
.registerPattern("template/*.stg");
|
||||
|
||||
@@ -50,7 +50,9 @@ public class ShellOptionMethodArgumentResolver extends AbstractArgumentMethodArg
|
||||
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
|
||||
ShellOption annot = parameter.getParameterAnnotation(ShellOption.class);
|
||||
Assert.state(annot != null, "No ShellOption annotation");
|
||||
List<String> names = Arrays.stream(annot.value()).map(v -> StringUtils.trimLeadingCharacter(v, '-')).collect(Collectors.toList());
|
||||
List<String> names = Arrays.stream(annot != null ? annot.value() : new String[0])
|
||||
.map(v -> StringUtils.trimLeadingCharacter(v, '-'))
|
||||
.collect(Collectors.toList());
|
||||
return new HeaderNamedValueInfo(annot, names);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user