[jira] Created: (CLI-156) Missing required options not throwing MissingOptionException

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (CLI-156) Missing required options not throwing MissingOptionException

ASF GitHub Bot (Jira)
Missing required options not throwing MissingOptionException
------------------------------------------------------------

                 Key: CLI-156
                 URL: https://issues.apache.org/jira/browse/CLI-156
             Project: Commons CLI
          Issue Type: Bug
          Components: CLI-1.x
    Affects Versions: 1.1
            Reporter: Jeremy Wilde
            Priority: Trivial


When an Options object is used to parse a second set of command arguments it won't throw a MissingOptionException.

{code:java}
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class Example
{
        public static void main(String[] args) throws ParseException
        {
                brokenExample();
                workingExample();
        }

        // throws exception as expected
        private static void workingExample() throws ParseException
        {
                String[] args = {};

                Options opts = new Options();
                opts.addOption(OptionBuilder.isRequired().create('v'));

                GnuParser parser = new GnuParser();
                CommandLine secondCL = parser.parse(opts, args);

                System.out.println("Done workingExample");
        }

        // fails to throw exception on second invocation of parse
        private static void brokenExample() throws ParseException
        {
                String[] firstArgs = { "-v" };
                String[] secondArgs = {};

                Options opts = new Options();
                opts.addOption(OptionBuilder.isRequired().create('v'));

                GnuParser parser = new GnuParser();
                CommandLine firstCL = parser.parse(opts, firstArgs);
                CommandLine secondCL = parser.parse(opts, secondArgs);

                System.out.println("Done brokenExample");
        }
}
{code}

This is a result of the Options object returning the reference to its own list and the parsers modifying that list. The first call is removing the required options as they are found and subsequent calls get back an empty list.

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

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CLI-156) Missing required options not throwing MissingOptionException

ASF GitHub Bot (Jira)

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

Henri Yandell commented on CLI-156:
-----------------------------------

Seems like it should be easy to solve by cloning the list before returning.

> Missing required options not throwing MissingOptionException
> ------------------------------------------------------------
>
>                 Key: CLI-156
>                 URL: https://issues.apache.org/jira/browse/CLI-156
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>    Affects Versions: 1.1
>            Reporter: Jeremy Wilde
>            Priority: Trivial
>             Fix For: 1.2
>
>
> When an Options object is used to parse a second set of command arguments it won't throw a MissingOptionException.
> {code:java}
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.Options;
> import org.apache.commons.cli.ParseException;
> public class Example
> {
> public static void main(String[] args) throws ParseException
> {
> brokenExample();
> workingExample();
> }
> // throws exception as expected
> private static void workingExample() throws ParseException
> {
> String[] args = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine secondCL = parser.parse(opts, args);
> System.out.println("Done workingExample");
> }
> // fails to throw exception on second invocation of parse
> private static void brokenExample() throws ParseException
> {
> String[] firstArgs = { "-v" };
> String[] secondArgs = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine firstCL = parser.parse(opts, firstArgs);
> CommandLine secondCL = parser.parse(opts, secondArgs);
> System.out.println("Done brokenExample");
> }
> }
> {code}
> This is a result of the Options object returning the reference to its own list and the parsers modifying that list. The first call is removing the required options as they are found and subsequent calls get back an empty list.

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

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CLI-156) Missing required options not throwing MissingOptionException

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Henri Yandell updated CLI-156:
------------------------------

    Fix Version/s: 1.2

> Missing required options not throwing MissingOptionException
> ------------------------------------------------------------
>
>                 Key: CLI-156
>                 URL: https://issues.apache.org/jira/browse/CLI-156
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>    Affects Versions: 1.1
>            Reporter: Jeremy Wilde
>            Priority: Trivial
>             Fix For: 1.2
>
>
> When an Options object is used to parse a second set of command arguments it won't throw a MissingOptionException.
> {code:java}
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.Options;
> import org.apache.commons.cli.ParseException;
> public class Example
> {
> public static void main(String[] args) throws ParseException
> {
> brokenExample();
> workingExample();
> }
> // throws exception as expected
> private static void workingExample() throws ParseException
> {
> String[] args = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine secondCL = parser.parse(opts, args);
> System.out.println("Done workingExample");
> }
> // fails to throw exception on second invocation of parse
> private static void brokenExample() throws ParseException
> {
> String[] firstArgs = { "-v" };
> String[] secondArgs = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine firstCL = parser.parse(opts, firstArgs);
> CommandLine secondCL = parser.parse(opts, secondArgs);
> System.out.println("Done brokenExample");
> }
> }
> {code}
> This is a result of the Options object returning the reference to its own list and the parsers modifying that list. The first call is removing the required options as they are found and subsequent calls get back an empty list.

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

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CLI-156) Missing required options not throwing MissingOptionException

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Emmanuel Bourg updated CLI-156:
-------------------------------

    Component/s:     (was: CLI-1.x)
                 Parser

Fixed, I cloned the list in the parser, it seemed better than cloning the list in the getter.

> Missing required options not throwing MissingOptionException
> ------------------------------------------------------------
>
>                 Key: CLI-156
>                 URL: https://issues.apache.org/jira/browse/CLI-156
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.1
>            Reporter: Jeremy Wilde
>            Priority: Trivial
>             Fix For: 1.2
>
>
> When an Options object is used to parse a second set of command arguments it won't throw a MissingOptionException.
> {code:java}
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.Options;
> import org.apache.commons.cli.ParseException;
> public class Example
> {
> public static void main(String[] args) throws ParseException
> {
> brokenExample();
> workingExample();
> }
> // throws exception as expected
> private static void workingExample() throws ParseException
> {
> String[] args = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine secondCL = parser.parse(opts, args);
> System.out.println("Done workingExample");
> }
> // fails to throw exception on second invocation of parse
> private static void brokenExample() throws ParseException
> {
> String[] firstArgs = { "-v" };
> String[] secondArgs = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine firstCL = parser.parse(opts, firstArgs);
> CommandLine secondCL = parser.parse(opts, secondArgs);
> System.out.println("Done brokenExample");
> }
> }
> {code}
> This is a result of the Options object returning the reference to its own list and the parsers modifying that list. The first call is removing the required options as they are found and subsequent calls get back an empty list.

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

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (CLI-156) Missing required options not throwing MissingOptionException

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Emmanuel Bourg resolved CLI-156.
--------------------------------

    Resolution: Fixed

> Missing required options not throwing MissingOptionException
> ------------------------------------------------------------
>
>                 Key: CLI-156
>                 URL: https://issues.apache.org/jira/browse/CLI-156
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.1
>            Reporter: Jeremy Wilde
>            Priority: Trivial
>             Fix For: 1.2
>
>
> When an Options object is used to parse a second set of command arguments it won't throw a MissingOptionException.
> {code:java}
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.Options;
> import org.apache.commons.cli.ParseException;
> public class Example
> {
> public static void main(String[] args) throws ParseException
> {
> brokenExample();
> workingExample();
> }
> // throws exception as expected
> private static void workingExample() throws ParseException
> {
> String[] args = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine secondCL = parser.parse(opts, args);
> System.out.println("Done workingExample");
> }
> // fails to throw exception on second invocation of parse
> private static void brokenExample() throws ParseException
> {
> String[] firstArgs = { "-v" };
> String[] secondArgs = {};
> Options opts = new Options();
> opts.addOption(OptionBuilder.isRequired().create('v'));
> GnuParser parser = new GnuParser();
> CommandLine firstCL = parser.parse(opts, firstArgs);
> CommandLine secondCL = parser.parse(opts, secondArgs);
> System.out.println("Done brokenExample");
> }
> }
> {code}
> This is a result of the Options object returning the reference to its own list and the parsers modifying that list. The first call is removing the required options as they are found and subsequent calls get back an empty list.

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