harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r571615 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/Integer.java test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
Date Fri, 31 Aug 2007 21:58:11 GMT
Author: tellison
Date: Fri Aug 31 14:58:10 2007
New Revision: 571615

URL: http://svn.apache.org/viewvc?rev=571615&view=rev
Log:
Fixes for throwing correct Integer decoding exceptions.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Integer.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Integer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Integer.java?rev=571615&r1=571614&r2=571615&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Integer.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Integer.java Fri
Aug 31 14:58:10 2007
@@ -160,19 +160,17 @@
                 return valueOf(0);
             }
             if ((firstDigit = string.charAt(i)) == 'x' || firstDigit == 'X') {
-                if (i == length) {
+                if (++i == length) {
                     throw new NumberFormatException(string);
                 }
-                i++;
                 base = 16;
             } else {
                 base = 8;
             }
         } else if (firstDigit == '#') {
-            if (i == length) {
+            if (++i == length) {
                 throw new NumberFormatException(string);
             }
-            i++;
             base = 16;
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java?rev=571615&r1=571614&r2=571615&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
Fri Aug 31 14:58:10 2007
@@ -145,6 +145,56 @@
             exception = true;
         }
         assertTrue("Failed to throw exception for 9999999999", exception);
+
+        try {
+            Integer.decode("-");
+            fail("Expected exception for -");
+        } catch (NumberFormatException e) {
+            // Expected
+        }
+
+        try {
+            Integer.decode("0x");
+            fail("Expected exception for 0x");
+        } catch (NumberFormatException e) {
+            // Expected
+        }
+
+        try {
+            Integer.decode("#");
+            fail("Expected exception for #");
+        } catch (NumberFormatException e) {
+            // Expected
+        }
+
+        try {
+            Integer.decode("x123");
+            fail("Expected exception for x123");
+        } catch (NumberFormatException e) {
+            // Expected
+        }
+
+        try {
+            Integer.decode(null);
+            fail("Expected exception for null");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            Integer.decode("");
+            fail("Expected exception for empty string");
+        } catch (NumberFormatException ex) {
+            // Expected
+        }
+
+        try {
+            Integer.decode(" ");
+            fail("Expected exception for single space");
+        } catch (NumberFormatException ex) {
+            // Expected
+        }
+
     }
 
     /**



Mime
View raw message