commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r711605 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/NumberUtils.java test/org/apache/commons/lang/NumberUtilsTest.java
Date Wed, 05 Nov 2008 16:33:26 GMT
Author: bayard
Date: Wed Nov  5 08:33:25 2008
New Revision: 711605

URL: http://svn.apache.org/viewvc?rev=711605&view=rev
Log:
Applying test/fix from LANG-457 - getting a StringIndexOutOfBounds from createNumber rather
than a NumberFormatException

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/NumberUtils.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/NumberUtilsTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/NumberUtils.java?rev=711605&r1=711604&r2=711605&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/NumberUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/NumberUtils.java Wed Nov  5
08:33:25 2008
@@ -142,6 +142,9 @@
         if (val.length() == 0) {
             throw new NumberFormatException("\"\" is not a valid number.");
         }
+        if (val.length() == 1 && !Character.isDigit(val.charAt(0))) {
+            throw new NumberFormatException(val + " is not a valid number.");
+        }
         if (val.startsWith("--")) {
             // this is protection for poorness in java.lang.BigDecimal.
             // it accepts this as a legal value, but it does not appear 

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/NumberUtilsTest.java?rev=711605&r1=711604&r2=711605&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/NumberUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/NumberUtilsTest.java Wed Nov
 5 08:33:25 2008
@@ -520,5 +520,17 @@
             fail( "Error calling public no-arg constructor" );
         }
     }
+
+    public void testLang457() {
+        String[] badInputs = new String[] { "l", "L", "f", "F", "junk", "bobL"};
+        for(int i=0; i<badInputs.length; i++) {
+            try {
+                NumberUtils.createNumber(badInputs[i]);
+                fail("NumberFormatException was expected for " + badInputs[i]);
+            } catch (NumberFormatException e) {
+                return; // expected
+            }
+        }
+    }
     
 }



Mime
View raw message