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

CommandSpec injected into Mixins doesn't have a CommandLine #439

Closed
zegelin opened this issue Aug 10, 2018 · 3 comments
Closed

CommandSpec injected into Mixins doesn't have a CommandLine #439

zegelin opened this issue Aug 10, 2018 · 3 comments
Milestone

Comments

@zegelin
Copy link

zegelin commented Aug 10, 2018

When a CommandSpec is injected into a @Mixin class, the CommandSpec.commandLine() method returns null.

This prevents custom setter methods from throwing ParameterExceptions, since the exception constructor requires a not-null CommandLine object.

    static class ExampleMixin {
        @Spec CommandSpec spec;

        @Option(names = "--trex")
        void setTRexFences(final String value) {
            throw new CommandLine.ParameterException(spec.commandLine(), "Didn't say the magic word.");
        }
    }

    static class ExampleCommand implements Callable<Void> {
        @Spec CommandSpec spec;

        @Option(names = "--raptor")
        void setRaptorFences(final String value) {
            throw new CommandLine.ParameterException(spec.commandLine(), "Didn't say the magic word.");
        }

        @Mixin
        ExampleMixin mixin;

        @Override
        public Void call() throws Exception {
            return null;
        }
    }

    public static void main(String[] args) {
        CommandLine.call(new ExampleCommand(), args);
    }

When run with --raptor off (an option in the root Callable):

Didn't say the magic word.

When run with --trex off (an option in the mixin):

Could not invoke void com.zegelin.SpecRepro$ExampleMixin.setTRexFences(java.lang.String) with off

The InvocationTargetException cause is a NPE, from the assert @ CommandLine.java:8852, since the spec commandline is null.

Version: 3.5.0

@remkop
Copy link
Owner

remkop commented Aug 10, 2018

Thanks for the bug report!
I overlooked this use case. :-(
I’ll look into it as soon as I can.

@remkop
Copy link
Owner

remkop commented Aug 11, 2018

Fixed in master.
I will do a release for this now.

@remkop
Copy link
Owner

remkop commented Aug 11, 2018

The fix is included in piococli-3.5.1. Enjoy!

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

No branches or pull requests

2 participants