Author: [email protected]
Date: Tue May 12 11:08:26 2009
New Revision: 5353

Modified:
    trunk/user/super/com/google/gwt/emul/java/lang/Long.java
    trunk/user/test/com/google/gwt/emultest/java/lang/LongTest.java

Log:
Fixes issue 3647: Long.parseLong("-") returns 0 instead of throwing a  
NumberFormatException.

Patch by: amitmanjhi
Review by: rjrjr (desk review)



Modified: trunk/user/super/com/google/gwt/emul/java/lang/Long.java
==============================================================================
--- trunk/user/super/com/google/gwt/emul/java/lang/Long.java    (original)
+++ trunk/user/super/com/google/gwt/emul/java/lang/Long.java    Tue May 12  
11:08:26 2009
@@ -122,6 +122,9 @@
      if (orig.charAt(0) == '-') {
        neg = true;
        s = orig.substring(1);
+      if (s.equals("")) { // orig = "-"
+        throw NumberFormatException.forInputString(orig);
+      }
      } else {
        s = orig;
      }

Modified: trunk/user/test/com/google/gwt/emultest/java/lang/LongTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/emultest/java/lang/LongTest.java      
(original)
+++ trunk/user/test/com/google/gwt/emultest/java/lang/LongTest.java     Tue May 
 
12 11:08:26 2009
@@ -87,7 +87,7 @@
      assertEquals(63, Long.numberOfTrailingZeros(Long.MIN_VALUE));
      assertEquals(20, Long.numberOfTrailingZeros(-0x7ff00000L));
    }
-
+
    public void testParse() {
      assertEquals(0L, Long.parseLong("0"));
      assertEquals(100000000000L, Long.parseLong("100000000000"));
@@ -108,6 +108,44 @@
      try {
        // Issue 2636
        new Long("");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      // issue 3647
+      Long.parseLong("-");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      // issue 3647
+      new Long("-");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      Long.parseLong(" -");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      new Long(" -");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      Long.parseLong("- ");
+      fail("expected NumberFormatException");
+    } catch (NumberFormatException ex) {
+      // expected
+    }
+    try {
+      new Long("- ");
        fail("expected NumberFormatException");
      } catch (NumberFormatException ex) {
        // expected

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to