Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ConcurrentModificationException while unregistering plugin in onDisable #494

@opl-

Description

@opl-

CommandAPI version

9.2.0

Minecraft version

1.19.4

Running Paper git-Paper-524 (MC: 1.19.4) (Git: 9846d0d)

Are you shading the CommandAPI?

Yes

What I did

Using the below test plugin which shades/shadows CommandAPI, and a plugin which allows unloading individual plugins (such as PlugmanX or ServerUtils), start the server as normal, then unload our test plugin.

@Override
public void onLoad() {
    CommandAPI.onLoad(
        CommandAPIBukkitConfig(this)
            .silentLogs(false)
            .verboseOutput(true)
    );
}

@Override
public void onEnable() {
    CommandAPI.onEnable();

    new CommandAPICommand("stuff")
        // This is where the command would go if I could find a case where it reliably breaks.
        .register();
}

@Override
public void onDisable() {
    CommandAPI.unregister("stuff");
    CommandAPI.onDisable();
}

What actually happened

The command was unregistered, but doing it left the following stack trace in the server logs:

[22:54:00 INFO]: [CommandAPI] Unregistering command /stuff
[22:54:00 ERROR]: Caught previously unhandled exception :
[22:54:00 ERROR]: Paper Async Command Builder Thread Pool - 0
java.util.ConcurrentModificationException: null
        at java.util.TreeMap$PrivateEntryIterator.nextEntry(Unknown Source) ~[?:?]
        at java.util.TreeMap$ValueIterator.next(Unknown Source) ~[?:?]
        at net.minecraft.commands.Commands.fillUsableCommands(Commands.java:475) ~[?:?]
        at net.minecraft.commands.Commands.sendAsync(Commands.java:441) ~[?:?]
        at net.minecraft.commands.Commands.lambda$sendCommands$5(Commands.java:414) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
        at java.lang.Thread.run(Unknown Source) ~[?:?]

Unfortunately, I've been unable to reliably reproduce it once I started. Maybe it's a race condition? That'd be fun!

What should have happened

Command /stuff should be unregistered without an exception.

Server logs and CommandAPI config

No response

Other

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions