Author: bayard Date: Fri Feb 20 05:00:59 2009 New Revision: 746137 URL: http://svn.apache.org/viewvc?rev=746137&view=rev Log: Applying additional patch to throw IllegalStateException when the specified width is not enough to fit the flags, indent and 1 character for the description. This closes out CLI-162 (for now :) ).
Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java?rev=746137&r1=746136&r2=746137&view=diff ============================================================================== --- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java (original) +++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java Fri Feb 20 05:00:59 2009 @@ -819,6 +819,13 @@ // characters final String padding = createPadding(nextLineTabStop); + if (nextLineTabStop >= width) + { + // stops infinite loop happening + throw new IllegalStateException("Total width is less than the width of the argument and indent " + + "- no room for the description"); + } + while (true) { text = padding + text.substring(pos).trim(); Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java?rev=746137&r1=746136&r2=746137&view=diff ============================================================================== --- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java (original) +++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java Fri Feb 20 05:00:59 2009 @@ -259,6 +259,14 @@ " yes.\n" + "Footer\n"; assertEquals( "Long arguments did not split as expected", expected, sw.toString() ); + + try { + formatter.printHelp(new PrintWriter(sw), 22, this.getClass().getName(), "Header", options, 0, 5, "Footer"); + fail("IllegalStateException expected"); + } catch(IllegalStateException ise) { + // expected + } + } }