Revxrsal / Lamp

A modern annotations-driven commands framework for Java and Kotlin
MIT License
202 stars 38 forks source link

Fix MissingArgumentException was not thrown with unspecified flag #20

Closed bivashy closed 2 years ago

bivashy commented 2 years ago

Example:

@Command("example")
public class ExampleCommand implements OrphanCommand {

    @Default
    public void onCommand(CommandActor actor,
            @Default("1") String anyArgument, @Flag("type") @Optional String type) {
        actor.reply("test");
    }
}

And if i write: /example anyText -type It will throw IndexOutOfBoundsException, not MissingArgumentException.

Stacktrace:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.LinkedList.checkElementIndex(Unknown Source)
at java.util.LinkedList.remove(Unknown Source)
at revxrsal.commands.core.BaseCommandDispatcher.handleFlag(BaseCommandDispatcher.java:188)
at revxrsal.commands.core.BaseCommandDispatcher.getMethodArguments(BaseCommandDispatcher.java:105)
at revxrsal.commands.core.BaseCommandDispatcher.execute(BaseCommandDispatcher.java:82)
at revxrsal.commands.core.BaseCommandDispatcher.searchCategory(BaseCommandDispatcher.java:69)
at revxrsal.commands.core.BaseCommandDispatcher.eval(BaseCommandDispatcher.java:44)
at revxrsal.commands.core.BaseCommandHandler.dispatch(BaseCommandHandler.java:475)

And i just replaced args.isEmpty with index check. And it`s working in the expected way.

Revxrsal commented 2 years ago

Looks good to me. Thanks!