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

Registering multi-dimensional (multiple subcommands) command arguments leads to a NPE #1625

Open
sero583 opened this issue Oct 3, 2020 · 2 comments

Comments

@sero583
Copy link
Contributor

sero583 commented Oct 3, 2020

Expected Behavior

It to work.

Actual Behavior

Throws an NPE when trying to join (cant join server).

Steps to Reproduce

new CommandParameter[][] {
            new CommandParameter[] {
                new CommandParameter("opt1", false, new String[] { "opt1" }),
                new CommandParameter("player", CommandParamType.TARGET, false)
            },
            new CommandParameter[] {
                new CommandParameter("opt2", false, new String[] { "opt2" }),
                new CommandParameter("player", CommandParamType.TARGET, false)
            },
            new CommandParameter[] {
                new CommandParameter("opt2", false, new String[] { "opt2" }),
                new CommandParameter("player", CommandParamType.TARGET, false)
            }
        };

Use this as a command parameter for a command and set it on a command class, see that when you join it will throw this NPE.

Crashdump, Backtrace or Other Files

java.lang.NullPointerException: null
        at cn.nukkit.network.protocol.AvailableCommandsPacket.lambda$encode$1(AvailableCommandsPacket.java:79) ~[nukkit.jar:?]
        at java.util.HashMap.forEach(Unknown Source) ~[?:1.8.0_192]
        at cn.nukkit.network.protocol.AvailableCommandsPacket.encode(AvailableCommandsPacket.java:68) ~[nukkit.jar:?]
        at cn.nukkit.Server.batchPackets(Server.java:689) ~[nukkit.jar:?]
        at cn.nukkit.network.RakNetInterface.putPacket(RakNetInterface.java:176) ~[nukkit.jar:?]
        at cn.nukkit.Player.dataPacket(Player.java:1063) ~[nukkit.jar:?]
        at cn.nukkit.Player.sendCommandData(Player.java:595) ~[nukkit.jar:?]
        at cn.nukkit.Player.setEnableClientCommand(Player.java:574) ~[nukkit.jar:?]
        at cn.nukkit.Player.doFirstSpawn(Player.java:842) ~[nukkit.jar:?]
        at cn.nukkit.Player.sendNextChunk(Player.java:834) ~[nukkit.jar:?]
        at cn.nukkit.Player.checkNetwork(Player.java:1836) ~[nukkit.jar:?]
        at cn.nukkit.Server.tick(Server.java:1165) ~[nukkit.jar:?]
        at cn.nukkit.Server.tickProcessor(Server.java:931) [nukkit.jar:?]
        at cn.nukkit.Server.start(Server.java:899) [nukkit.jar:?]
        at cn.nukkit.Server.<init>(Server.java:580) [nukkit.jar:?]
        at cn.nukkit.Nukkit.main(Nukkit.java:120) [nukkit.jar:?]
@Sleepybear
Copy link
Collaborator

I believe you need to have a key for each parameter.

Try doing something like:

Map<String, CommandParameter[]> params = new HashMap<>();
params.put("opt1", 
    new CommandParameter[] {
                new CommandParameter("opt1", false, new String[] { "opt1" }),
                new CommandParameter("player", CommandParamType.TARGET, false)
            });
params.put("opt2", 
            new CommandParameter[] {
                new CommandParameter("opt2", false, new String[] { "opt2" }),
                new CommandParameter("player", CommandParamType.TARGET, false)
            });

It shouldn't matter what the key names are, as long as they are unique.

@sero583
Copy link
Contributor Author

sero583 commented Oct 4, 2020

There is actually a key for it, but its numeric, anyway when putting the integer key inside (with a loop) it will throw this NPE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants