commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLI-225) Special properties option (-Dproperty=value) handled improperly
Date Wed, 06 Feb 2013 12:25:13 GMT

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

Thomas Neidhart commented on CLI-225:
-------------------------------------

I would not consider this to be a bug, e.g. the java program also supports this kind of argument:

{noformat}
  java -Dmy.test MyTest
{noformat}

will produce the following output:

{noformat}
  System.out.println("my.test = '" + System.getProperty("my.test") + "'");
{noformat}

{noformat}
  my.test = ''
{noformat}

when not providing the -Dmy.test the result is null:

{noformat}
  my.test = 'null'
{noformat}


As I have written before, one must be careful when iterating over the resulting option values,
but I see this as a feature (to support setting a key without a value) rather than a bug.
                
> Special properties option (-Dproperty=value) handled improperly
> ---------------------------------------------------------------
>
>                 Key: CLI-225
>                 URL: https://issues.apache.org/jira/browse/CLI-225
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Alexey Tsvetkov
>
> In CLI 1.2 the special properties option (-Dproperty=value) is handled improperly. In
GnuParser.java from line 80 is as follows:
> {code}
>                     if (opt.indexOf('=') != -1 && options.hasOption(opt.substring(0,
opt.indexOf('='))))
>                     {
>                         // the format is --foo=value or -foo=value
>                         tokens.add(arg.substring(0, arg.indexOf('='))); // --foo
>                         tokens.add(arg.substring(arg.indexOf('=') + 1)); // value
>                     }
>                     else if (options.hasOption(arg.substring(0, 2)))
>                     {
>                         // the format is a special properties option (-Dproperty=value)
>                         tokens.add(arg.substring(0, 2)); // -D
>                         tokens.add(arg.substring(2)); // property=value
>                     }
> {code}
> , but should be:
> {code}
>                     if (opt.indexOf('=') != -1)
>                 	{
>                 	    if (options.hasOption(opt.substring(0, opt.indexOf('='))))
> 	                    {
> 	                        // the format is --foo=value or -foo=value
> 	                        tokens.add(arg.substring(0, arg.indexOf('='))); // --foo
> 	                        tokens.add(arg.substring(arg.indexOf('=') + 1)); // value
> 	                    }
> 	                    else if (options.hasOption(arg.substring(0, 2)))
> 	                    {
> 	                        // the format is a special properties option (-Dproperty=value)
> 	                        tokens.add(arg.substring(0, 2)); // -D
> 	                        tokens.add(arg.substring(2)); // property=value
> 	                    }
>                 	}
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message