You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Emmanuel Bourg (JIRA)" <ji...@apache.org> on 2008/07/25 14:21:31 UTC

[jira] Created: (CLI-162) infinite loop in the wrapping code of HelpFormatter

infinite loop in the wrapping code of HelpFormatter
---------------------------------------------------

                 Key: CLI-162
                 URL: https://issues.apache.org/jira/browse/CLI-162
             Project: Commons CLI
          Issue Type: Bug
          Components: Help formatter
    Affects Versions: 1.1
            Reporter: Emmanuel Bourg
             Fix For: 1.3


If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.

Test case:

{code}
Options options = new Options();
options.addOption("h", "help", false, "This is a looooong description");

HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(20);
formatter.printHelp("app", options); // hang & crash
{code}

An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Reopened: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary Gregory reopened CLI-162:
------------------------------


Committed new test in BugCLI162Test. The class BugCLI162Test is not invoked during a Maven build BTW.

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Commented: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674469#action_12674469 ] 

Henri Yandell commented on CLI-162:
-----------------------------------


Two of the options appear to be problematic in CLI162.

The first is OPT_PASSWORD. In this the url is longer than the allowed width of the screen, so some kind of failure needs to happen - or the url needs to be mercilessly chopped. This is the one that goes into an infinite loop due to CLI-151. My gut feeling from the code is that CLI-151 didn't introduce this bug, but you had to be significantly longer to hit the bug before (ie: printTabStop longer than the width).

The second is OPT_PARAM_TYPES_INT + OPT_PARAM_TYPES_NAME, it shows the the patch for this ticket contained a bug when the lastPos happened to equal the firstPos for completely normal reasons. I'd missed that pos was already set to a real value when the loop was begun and not to 0. I'm not sure why both options have to be set for this to happen. 

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Commented: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674473#action_12674473 ] 

Henri Yandell commented on CLI-162:
-----------------------------------

svn ci -m "Applying my second attempt at a patch to CLI-162. This fixes Gary's reported bug (one of which was an example of CLI-162, and one a bug in my first attempt to patch). Open question is whether to output text that is too long, or try and break it up to fit the screen width. "

Sending        src/java/org/apache/commons/cli/HelpFormatter.java
Sending        src/test/org/apache/commons/cli/bug/BugCLI162Test.java
Transmitting file data ..
Committed revision 745388.

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>         Attachments: CLI-162-take2.patch
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Closed: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed CLI-162.
-----------------------------

    Resolution: Fixed

Throw IllegalStateException on last infinite loop test case.


svn ci -m "Applying additional patch to throw IllegalStateException when the speci
fied width is not enough to fit the flags, indent and 1 character for the description. This closes out CLI-162 (for now :) ). "
Sending        src/java/org/apache/commons/cli/HelpFormatter.java
Sending        src/test/org/apache/commons/cli/bug/BugCLI162Test.java
Transmitting file data ..
Committed revision 746137.

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>         Attachments: CLI-162-additional.patch, CLI-162-take2.patch
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Commented: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675241#action_12675241 ] 

Henri Yandell commented on CLI-162:
-----------------------------------

Ended up modifying this to break it up to fit screen width.

Discovered another infinite loop issue if the entered width is smaller than the nextTabStop (ie: argument + indent). 

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>         Attachments: CLI-162-additional.patch, CLI-162-take2.patch
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Closed: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed CLI-162.
-----------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 1.3)
                   1.2

svn ci -m "Changing the current OutOfMemoryError to a RuntimeException per CLI-162. A new ticket for the RuntimeException is at CLI-174" 

Sending        src/java/org/apache/commons/cli/HelpFormatter.java
Adding         src/test/org/apache/commons/cli/bug/BugCLI162Test.java
Transmitting file data ..
Committed revision 735257.

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Updated: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated CLI-162:
------------------------------

    Attachment: CLI-162-take2.patch

Attaching patch that rolls back the previous RuntimeException throwing. The if statement in that patch was testing the wrong condition. This patch adds the correct condition, and rather than throwing an exception the text is simply outputted irregardless of the fact it is over the width. What should happen is debatable here - due to a side-effect of CLI-151, we can't do anything aggressive here because things were printing out happily if they were under width + printTabStop. Our options are either to just print, or to forcibly break the text. 

The test code no longer expects to get a RuntimeException.

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>         Attachments: CLI-162-take2.patch
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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


[jira] Updated: (CLI-162) infinite loop in the wrapping code of HelpFormatter

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated CLI-162:
------------------------------

    Attachment: CLI-162-additional.patch

> infinite loop in the wrapping code of HelpFormatter
> ---------------------------------------------------
>
>                 Key: CLI-162
>                 URL: https://issues.apache.org/jira/browse/CLI-162
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>             Fix For: 1.2
>
>         Attachments: CLI-162-additional.patch, CLI-162-take2.patch
>
>
> If there is not enough space to display a word on a single line, HelpFormatter goes into a infinite loops until the JVM crashes with an OutOfMemoryError.
> Test case:
> {code}
> Options options = new Options();
> options.addOption("h", "help", false, "This is a looooong description");
> HelpFormatter formatter = new HelpFormatter();
> formatter.setWidth(20);
> formatter.printHelp("app", options); // hang & crash
> {code}
> An helpful exception indicating the insufficient width would be more appropriate than an OutOfMemoryError.

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