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

Gary D. Gregory commented on CLI-349:
-------------------------------------

Hello [~leofernandesmo] 

Thank you for your report.

If you use a recent version of Java, you get:
{noformat}
java.lang.NullPointerException: Cannot invoke 
"org.apache.commons.cli.Options.getRequiredOptions()" because "options" is null
        at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:747)
        ...
 {noformat}
Which is the most precise exception and message you'll receive from Java.

Nevertheless, we can make this a touch better using Java's 
{{Objects.requireNonNull()}} to fail faster. The exception is still an NPE, the 
most precise for this case.

Done in git master and snapshot builds in 
[https://repository.apache.org/content/repositories/snapshots/commons-cli/commons-cli/1.10.0-SNAPSHOT/]

> DefaultParser.parse() throws NullPointerException when options parameter is 
> null
> --------------------------------------------------------------------------------
>
>                 Key: CLI-349
>                 URL: https://issues.apache.org/jira/browse/CLI-349
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Options definition, Parser
>    Affects Versions: 1.9.0
>            Reporter: Leo Fernandes
>            Priority: Major
>              Labels: NPE, NullPointerException
>
> The DefaultParser.parse() method throws a NullPointerException when the 
> options parameter is null.
> Steps to reproduce:
> 1. Create a DefaultParser instance
> 2. Call parse() with null options parameter: Eg.: 
> {code:java}
> defaultParser0.parse((Options) null, stringArray0, getBooleanJazzer());{code}
> 3. NPE is thrown at line DefaultParser.java:708: 
> {code:java}
> expectedOpts = new ArrayList<>(options.getRequiredOptions());{code}
>  
>  
> Expected behavior: The method should validate input parameters and throw a 
> meaningful IllegalArgumentException with a descriptive message.



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

Reply via email to