Name: krT82822 Date: 12/04/99 12/4/99 eval1127@eng -- still an issue as of kestrel RA (1.3.0 build "I"). (Bug 4242173 seemed to suggest this might have been fixed by now.) java version "1.3beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O) Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode) The parseInt() method of the Integer primitive wrapper class does not recognize a unary plus as a parseable character. This code: <p><pre> String deltaString = "+93"; int delta = Integer.parseInt(deltaString); </pre><p> throws the following exception: <p></pre> java.lang.NumberFormatException: +93 at java.lang.Integer.parseInt(Integer.java:409) at java.lang.Integer.parseInt(Integer.java:458) </pre><p> The code for Integer.parseInt() contains this fragment: <p><pre> digit = Character.digit(s.charAt(i++),radix); if (digit < 0) { throw new NumberFormatException(s) </pre><p> which will cause the above exception. The code looks for the minus sign and bumps the parsing index up; it should also include a test for a plus sign. (Review ID: 98621) ====================================================================== Name: rlT66838 Date: 03/17/2000 all versions Integer.parseInt does not handle strings like "+123". While this appears to be deliberate (and therefore not a bug) I think it is silly. Why not allow it to handle explicit positives? Integer.parseInt("123") ; // works Integer.parseInt("-123"); // works Integer.parseInt("+123"); // throws NumberFormatException (Review ID: 102607) ======================================================================
|