You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sruteesh Kumar Paramata (Jira)" <ji...@apache.org> on 2023/07/31 16:07:00 UTC

[jira] [Comment Edited] (CLI-317) NullPointerException thrown by CommandLineParser.parse()

    [ https://issues.apache.org/jira/browse/CLI-317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17749254#comment-17749254 ] 

Sruteesh Kumar Paramata edited comment on CLI-317 at 7/31/23 4:06 PM:
----------------------------------------------------------------------

[~PhBastiani] 

Should it really throw an exception?

It has to consider bar as a value for the option foo. Correct?

 


was (Author: JIRAUSER301594):
Should it really throw an exception?

 

> NullPointerException thrown by CommandLineParser.parse()
> --------------------------------------------------------
>
>                 Key: CLI-317
>                 URL: https://issues.apache.org/jira/browse/CLI-317
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.5.0
>            Reporter: Philippe Bastiani
>            Priority: Critical
>              Labels: exception
>
> # First at all, your *testAmbiguousLongWithoutEqualSingleDash* does not lead to a AmbiguousOptionException
>  # For this same test, if I replace the deprecated OptionBuilder with Option.Builder as follows
> {code:java}
> options.addOption(Option.builder().option("f").longOpt("foo").optionalArg(true).build());
> options.addOption(Option.builder().option("b").longOpt("bar").optionalArg(false).build());
> {code}
> the test leads to a NPE
> {code:java}
> java.lang.NullPointerException
> 	at xx.DefaultParser.handleShortAndLongOption(DefaultParser.java:476)
> 	at xx.DefaultParser.handleToken(DefaultParser.java:535)
> 	at xx.DefaultParser.parse(DefaultParser.java:714)
> 	at xx.DefaultParser.parse(DefaultParser.java:677)
> 	at xx.DefaultParser.parse(DefaultParser.java:654)
> {code}
> _Note_  : tested with Github code (January 22, 2023)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)