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

NPE on command parse #141

Closed
maximdim opened this issue Jun 7, 2017 · 2 comments
Closed

NPE on command parse #141

maximdim opened this issue Jun 7, 2017 · 2 comments
Assignees
Milestone

Comments

@maximdim
Copy link

maximdim commented Jun 7, 2017

    <dependency>
      <groupId>info.picocli</groupId>
      <artifactId>picocli</artifactId>
      <version>0.9.6</version>
    </dependency>
import picocli.CommandLine;
import picocli.CommandLine.Option;

public class A {
    @Option(names = { "-u", "--user" }, required = true, description = "user id")
    private String user;

    @Option(names = { "-p", "--password" }, required = true, description = "password")
    private String password;

    public static void main(String[] args) {
        A a = new A();
        CommandLine commandLine = new CommandLine(a);
        commandLine.parse("-u", "foo");
    }
}

Leads to the following exception on run:

Exception in thread "main" java.lang.NullPointerException
	at picocli.CommandLine$PositionalParametersSorter.compare(CommandLine.java:1581)
	at picocli.CommandLine$PositionalParametersSorter.compare(CommandLine.java:1579)
	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.util.TimSort.sort(TimSort.java:220)
	at java.util.Arrays.sort(Arrays.java:1512)
	at java.util.ArrayList.sort(ArrayList.java:1454)
	at java.util.Collections.sort(Collections.java:175)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1097)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1090)
	at picocli.CommandLine.parse(CommandLine.java:191)
	at com.bmo.channels.bitbucket.A.main(A.java:16)
@remkop
Copy link
Owner

remkop commented Jun 7, 2017

Thanks for the bug report! Commuting now, will check asap.

@remkop
Copy link
Owner

remkop commented Jun 7, 2017

The issue has been fixed and is included in the new 0.9.7 release.
The example will now throw a MissingParameterException "Missing required option 'password'", which I believe is correct behaviour.

Please verify and let me know of any issues.

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