Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when autocompletion using /execute run <command> #310

Open
Jiogo18 opened this issue Jul 29, 2022 · 0 comments
Open
Labels
bug Something isn't working currently hotfixed Something that's fixed/implemented but not fixed properly

Comments

@Jiogo18
Copy link

Jiogo18 commented Jul 29, 2022

CommandAPI version

8.5.0

Minecraft version

1.16

Are you shading the CommandAPI?

No

What I did

  • I created a command using a CustomArgument and a StringArgument (the second one has suggestions).
		ArgumentSuggestions suggestFoo = (i, b) -> b.suggest("foo").buildFuture();
		ResultingCommandExecutor executor = (sender, args) -> {
			sender.sendMessage("ok");
			return 1;
		};
		new CommandAPICommand("test_error")
			.withArguments(
				new CustomArgument<String, String>(new StringArgument("arg1"), info -> info.input()),
				new StringArgument("arg2")
					.replaceSuggestions(suggestFoo))
			.executes(executor)
			.register();
  • Then I tried these commands:
    • /test_error arg1 arg2
    • /execute run test_error arg1 arg2
    • /execute store result score result tests run test_error arg1 arg2

What actually happened

  • ✔️ These commands are executing (with command block/chat) and return 1 in the score "tests/result".
  • ❌ But for the 2 last commands, I get a NullPointerException when completing the second argument.
[16:15:22 FATAL]: Error executing task on Server
java.lang.NullPointerException: Cannot invoke "com.mojang.brigadier.context.ParsedArgument.getRange()" because the return value of "java.util.Map.get(Object)" is null
        at dev.jorel.commandapi.CommandAPIHandler.getRawArgumentInput(CommandAPIHandler.java:132) ~[?:?]
        at dev.jorel.commandapi.arguments.CustomArgument.parseArgument(CustomArgument.java:137) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.parseArgument(CommandAPIHandler.java:379) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.generatePreviousArguments(CommandAPIHandler.java:886) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.lambda$toSuggestions$7(CommandAPIHandler.java:909) ~[?:?]
        at com.mojang.brigadier.tree.ArgumentCommandNode.listSuggestions(ArgumentCommandNode.java:71) ~[patched_1.16.5.jar:git-Paper-794]
        at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:596) ~[patched_1.16.5.jar:git-Paper-794]
        at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:579) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.PlayerConnection.lambda$a$7(PlayerConnection.java:794) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1271) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1264) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1225) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1139) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-794]
        at java.lang.Thread.run(Thread.java:833) [?:?]
There is more when pressing tab in the console
[16:11:52 WARN]: Unhandled exception when tab completing
java.util.concurrent.ExecutionException: org.bukkit.command.CommandException: Unhandled exception executing tab-completer for 'execute run test_error s ' in org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper(execute)
        at org.bukkit.craftbukkit.v1_16_R3.util.Waitable.get(Waitable.java:42) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.ConsoleCommandCompleter.complete(ConsoleCommandCompleter.java:103) ~[patched_1.16.5.jar:git-Paper-794]
        at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4147) ~[patched_1.16.5.jar:git-Paper-794]
        at org.jline.reader.impl.LineReaderImpl.expandOrComplete(LineReaderImpl.java:4060) ~[patched_1.16.5.jar:git-Paper-794]
        at org.jline.reader.impl.LineReaderImpl$1.apply(LineReaderImpl.java:3630) ~[patched_1.16.5.jar:git-Paper-794]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:603) ~[patched_1.16.5.jar:git-Paper-794]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:418) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecrell.terminalconsole.SimpleTerminalConsole.readCommands(SimpleTerminalConsole.java:158) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecrell.terminalconsole.SimpleTerminalConsole.start(SimpleTerminalConsole.java:141) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.DedicatedServer$1.run(DedicatedServer.java:106) ~[patched_1.16.5.jar:git-Paper-794]
Caused by: org.bukkit.command.CommandException: Unhandled exception executing tab-completer for 'execute run test_error s ' in org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper(execute)
        at org.bukkit.command.SimpleCommandMap.tabComplete(SimpleCommandMap.java:250) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.command.SimpleCommandMap.tabComplete(SimpleCommandMap.java:195) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.ConsoleCommandCompleter$2.evaluate(ConsoleCommandCompleter.java:93) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.ConsoleCommandCompleter$2.evaluate(ConsoleCommandCompleter.java:90) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.util.Waitable.run(Waitable.java:24) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.b(MinecraftServer.java:1447) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:436) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1347) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1135) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-794]
        at java.lang.Thread.run(Thread.java:833) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "com.mojang.brigadier.context.ParsedArgument.getRange()" because the return value of "java.util.Map.get(Object)" is null
        at dev.jorel.commandapi.CommandAPIHandler.getRawArgumentInput(CommandAPIHandler.java:132) ~[?:?]
        at dev.jorel.commandapi.arguments.CustomArgument.parseArgument(CustomArgument.java:137) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.parseArgument(CommandAPIHandler.java:379) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.generatePreviousArguments(CommandAPIHandler.java:886) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.lambda$toSuggestions$7(CommandAPIHandler.java:909) ~[?:?]
        at com.mojang.brigadier.tree.ArgumentCommandNode.listSuggestions(ArgumentCommandNode.java:71) ~[patched_1.16.5.jar:git-Paper-794]
        at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:596) ~[patched_1.16.5.jar:git-Paper-794]
        at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:579) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper.tabComplete(VanillaCommandWrapper.java:59) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.command.SimpleCommandMap.tabComplete(SimpleCommandMap.java:244) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.command.SimpleCommandMap.tabComplete(SimpleCommandMap.java:195) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.ConsoleCommandCompleter$2.evaluate(ConsoleCommandCompleter.java:93) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.command.ConsoleCommandCompleter$2.evaluate(ConsoleCommandCompleter.java:90) ~[patched_1.16.5.jar:git-Paper-794]
        at org.bukkit.craftbukkit.v1_16_R3.util.Waitable.run(Waitable.java:24) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.b(MinecraftServer.java:1447) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:436) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1347) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1135) ~[patched_1.16.5.jar:git-Paper-794]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-794]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

What should have happened

No NullPointerException when suggesting "foo" for the second argument.

Server logs and CommandAPI config

config.yml
################################################################################
# Logging                                                                      #
################################################################################

# Verbose outputs (default: false)
# If "true", outputs command registration and unregistration logs in the console
verbose-outputs: false

# Silent logs (default: false)
# If "true", turns off all logging from the CommandAPI, except for errors.
silent-logs: false

################################################################################
# Messages                                                                     #
################################################################################

# Messages
# Controls messages that the CommandAPI displays to players
messages:

  # Missing executor implementation (default: "This command has no implementations for %s")
  # The message to display to senders when a command has no executor. Available
  # parameters are:
  #   %s - the executor class (lowercase)
  #   %S - the executor class (normal case)
  missing-executor-implementation: "This command has no implementations for %s"

################################################################################
# Debugging                                                                    #
################################################################################

# Create dispatcher JSON (default: false)
# If "true", the CommandAPI creates a command_registration.json file showing the
# mapping of registered commands. This is designed to be used by developers -
# setting this to "false" will improve command registration performance.
create-dispatcher-json: false

# Use latest version (default: false)
# If "true", the CommandAPI will use the latest available NMS implementation
# when the CommandAPI is used. This avoids all checks to see if the latest NMS
# implementation is actually compatible with the current Minecraft version.
use-latest-nms-version: false

################################################################################
# Command conversion                                                           #
################################################################################
[Uploading config.yml…]()

# Plugins to convert (default: [])
# Controls the list of plugins to process for command conversion.
plugins-to-convert: []

# Other commands to convert (default: [])
# A list of other commands to convert. This should be used for commands which
# are not declared in a plugin.yml file.
other-commands-to-convert: []

# Skip sender proxy (default: [])
# Determines whether the proxy sender should be skipped when converting a
# command. If you are having issues with plugin command conversion, add the
# plugin to this list.
skip-sender-proxy: []

Going further

I have tried with a CommandTree and a CommandAPICommand, the result is the same. Also this appends when there is a CustomArgument followed by any argument with suggestions.
		ArgumentSuggestions suggestFoo = (i, b) -> b.suggest("foo").buildFuture();
		ResultingCommandExecutor executor = (sender, args) -> {
			sender.sendMessage("ok");
			return 1;
		};
		new CommandAPICommand("test_error") // error
			.withArguments(
				new CustomArgument<String, String>(new StringArgument("arg1"), info -> info.input()),
				new StringArgument("arg2")
					.replaceSuggestions(suggestFoo))
			.executes(executor)
			.register();
		new CommandTree("test_error2")
			.then(new LiteralArgument("string_string") // ok
					.then(new StringArgument("arg1")
							.then(new StringArgument("arg2")
									.replaceSuggestions(suggestFoo)
									.executes(executor))))
			.then(new LiteralArgument("string_custom") // ok
					.then(new StringArgument("arg1")
							.then(new CustomArgument<String, String>(new StringArgument("arg2"), info -> info.input())
									.replaceSuggestions(suggestFoo)
									.executes(executor))))
			.then(new LiteralArgument("custom_string") // error
					.then(new CustomArgument<String, String>(new StringArgument("arg1"), info -> info.input())
							.then(new StringArgument("arg2")
									.replaceSuggestions(suggestFoo)
									.executes(executor))))
			.then(new LiteralArgument("custom_custom") // error
					.then(new CustomArgument<String, String>(new StringArgument("arg1"), info -> info.input())
							.then(new CustomArgument<String, String>(new StringArgument("arg2"), info -> info.input())
									.replaceSuggestions(suggestFoo)
									.executes(executor))))
			.register();

Other

No response

@Jiogo18 Jiogo18 added the bug Something isn't working label Jul 29, 2022
JorelAli added a commit that referenced this issue Dec 17, 2022
I'm not entirely sure what the best thing to return here is, but I thought I'd put a TODO so this doesn't go unnoticed for 9.0.0's release.
JorelAli added a commit that referenced this issue Dec 19, 2022
@JorelAli JorelAli added the currently hotfixed Something that's fixed/implemented but not fixed properly label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working currently hotfixed Something that's fixed/implemented but not fixed properly
Projects
None yet
Development

No branches or pull requests

2 participants