Fix empty command chain causing NullPointerException (#1931)

* Fix empty command chain causing NullPointerException

* Add test for empty command input

(cherry picked from commit 3645d4311d)
(cherry picked from commit e2efdbb427)
This commit is contained in:
Spanner 2023-09-01 21:14:18 +00:00 committed by Matt Worzala
parent 6805c903f3
commit 2be361448f

View File

@ -97,18 +97,19 @@ final class CommandParserImpl implements CommandParser {
NodeResult result = parseNode(sender, parent, chain, reader);
chain = result.chain;
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
NodeResult lastNodeResult = chain.nodeResults.peekLast();
Node lastNode = lastNodeResult.node;
NodeResult lastNodeResult = chain.nodeResults.peekLast();
if (lastNodeResult == null) return UnknownCommandResult.INSTANCE;
Node lastNode = lastNodeResult.node;
if (result.argumentResult instanceof ArgumentResult.Success<?>) {
CommandExecutor executor = nullSafeGetter(lastNode.execution(), Graph.Execution::executor);
if (executor != null) return ValidCommand.executor(input, chain, executor);
}
// If here, then the command failed or didn't have an executor
// Look for a default executor, or give up if we got nowhere
NodeResult lastNode = chain.nodeResults.peekLast();
if (lastNode.node.equals(parent)) return UnknownCommandResult.INSTANCE;
if (lastNode.equals(parent)) return UnknownCommandResult.INSTANCE;
if (chain.defaultExecutor != null) {
return ValidCommand.defaultExecutor(input, chain);
}