Fix warnings

- Fix some potential NPE cases.
- Fix warnings for missing @Nullable
This commit is contained in:
Janne Valkealahti
2022-11-19 15:08:49 +00:00
parent 83fb5f71fc
commit ee7a9da4aa
11 changed files with 48 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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));
}