Re: Integer.parseInt("+42") gives -42

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/05/2008, Andrew John Hughes <gnu_andrew@xxxxxxxxxxxxxx> wrote:
> On 12/05/2008, Tom Tromey <tromey@xxxxxxxxxx> wrote:
>  > >>>>> "David" == David Daney <ddaney@xxxxxxxxxx> writes:
>  >
>  >  David> I am not an expert in this realm, but this may be small enough
>  >  David> so that an assignment is not necessary.
>  >
>  >  Yes, I agree, particularly because there is really only one fix for
>  >  this -- delete the '+' code.
>
>
> It would be small enough, was this his only contribution.  But his
>  mention of commit rights implies previous contributions and there are
>  several ChangeLog entries:
>
>  ChangeLog-2005:2005-12-18  Nicolas Geoffray <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-12-14  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-12-04  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-12-04  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-12-03  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-10-28  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-10-21  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005:2005-10-21  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>  ChangeLog-2005: Reported by Nicolas Geoffray  <nicolas.geoffray@xxxxxxx>
>  ChangeLog-2006:2006-01-16  Nicolas Geoffray  <nicolas.geoffray@xxxxxxxxxxx>
>
>  This does imply to me that he already has an assignment, but either he
>  or mjw needs to confirm this.
>
>
>  Actually, the proposed patch doesn't
>  >  seem to go far enough in that direction... AFAICT a leading '+' is not
>  >  allowed at all; there's no reason to check for it specially.
>  >
>  >
>  >  Tom
>  >
>
>
> This strikes me as odd too, but I haven't yet had chance to test the
>  code itself against OpenJDK.
>
> --
>  Andrew :-)
>
>  Support Free Java!
>  Contribute to GNU Classpath and the OpenJDK
>  http://www.gnu.org/software/classpath
>  http://openjdk.java.net
>
>  PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
>  Fingerprint: F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
>

Interestingly, our parseInt Mauve test has this:

    // In JDK1.7, '+' is considered a valid character.
    try
      {
        i = Integer.parseInt("+10");
        harness.check(true);
      }
    catch (NumberFormatException nfe)
      {
        harness.fail("Leading '+' does not throw NumberFormatException");
      }

and indeed it does return 42 (so Classpath is still wrong returning
-42).  OpenJDK6 throws an exception:

Exception in thread "main" java.lang.NumberFormatException: For input
string: "+42"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:470)
        at java.lang.Integer.parseInt(Integer.java:514)
        at TestPlusPrefix.main(TestPlusPrefix.java:5)
-- 
Andrew :-)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net

PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux