Author: bayard
Date: Sat Jan 17 01:30:53 2009
New Revision: 735257

URL: http://svn.apache.org/viewvc?rev=735257&view=rev
Log:
Changing the current OutOfMemoryError to a RuntimeException per CLI-162. A new 
ticket for the RuntimeException is at CLI-174

Added:
    
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java
   (with props)
Modified:
    
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.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=735257&r1=735256&r2=735257&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
 Sat Jan 17 01:30:53 2009
@@ -821,6 +821,7 @@
 
         while (true)
         {
+            int lastPos = pos;
             text = padding + text.substring(pos).trim();
             pos = findWrapPos(text, width, 0);
 
@@ -829,6 +830,10 @@
                 sb.append(text);
 
                 return sb;
+            } else
+            if (pos == lastPos)
+            {
+                throw new RuntimeException("Text too long for line - throwing 
exception to avoid infinite loop [CLI-162]: " + text);
             }
 
             sb.append(rtrim(text.substring(0, pos))).append(defaultNewLine);

Added: 
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=735257&view=auto
==============================================================================
--- 
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java
 (added)
+++ 
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java
 Sat Jan 17 01:30:53 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.cli.bug;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.MissingArgumentException;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+
+import junit.framework.TestCase;
+
+public class BugCLI162Test extends TestCase {
+
+    private Options options;
+
+    public void setUp() {
+        options = new Options();
+        options.addOption("h", "help", false, "This is a looooong 
description");
+    }
+
+    public void testInfiniteLoop() {
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.setWidth(20);
+        try {
+            formatter.printHelp("app", options); // hang & crash
+        } catch(RuntimeException re) {
+            assertTrue(re.getMessage().startsWith("Text too long for line - 
throwing exception to avoid infinite loop [CLI-162]: "));
+        }
+    }
+
+}

Propchange: 
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI162Test.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to