commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (CLI-206) If Parser.parse is called with a Properties parameter that contains an option not defined, get a NPE
Date Fri, 16 Jul 2010 07:25:51 GMT

     [ https://issues.apache.org/jira/browse/CLI-206?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Emmanuel Bourg resolved CLI-206.
--------------------------------

    Resolution: Duplicate

> If Parser.parse is called with a Properties parameter that contains an option not defined,
get a NPE
> ----------------------------------------------------------------------------------------------------
>
>                 Key: CLI-206
>                 URL: https://issues.apache.org/jira/browse/CLI-206
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.2
>            Reporter: Denis Haskin
>             Fix For: 1.3
>
>
> See junit test below.
> The problems appears to be in org.apache.commons.cli.Parser.processProperties, around
lines 252 - 259.
> It's trying to get the Option object for the property's name, but if none was specified,
then opt is null and the attempt to call opt.hasArg() at line 259 throws an NPE.
> The fix should be to skip the remainder of the clause if the Option object is null.
> Example unit test:
> {code:java}
> package test;
> import java.util.Properties;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.Options;
> import org.apache.commons.cli.PosixParser;
> import org.junit.Test;
> public class CommonsCliBugTest {
>     @Test
>     public void testCommonsCliOkay() throws Exception {
>         String[] args = new String[] {};
>         Properties p = new Properties();
>         p.setProperty("alpha", "beta");
>         Options options = new Options();
>         options.addOption(OptionBuilder.withLongOpt("alpha").hasArg().withArgName("ALPHA").create());
>         PosixParser parser = new PosixParser();
>         parser.parse(options, args, p);
>     }
>     @Test
>     public void testCommonsCliFails() throws Exception {
>         String[] args = new String[] {};
>         Properties p = new Properties();
>         // Note this property is not specified as a valid option
>         p.setProperty("gamma", "beta");
>         Options options = new Options();
>         options.addOption(OptionBuilder.withLongOpt("alpha").hasArg().withArgName("ALPHA").create());
>         PosixParser parser = new PosixParser();
>         parser.parse(options, args, p);
>     }
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message