I will now teach you how to fish my lad First, you have the source code to all the java classes. It's in a jar file called src.jar, in your jdk folder. Open it up and take a look at the Integer class, then scroll down to the parse() method. You'll see that parse(String) calls parse(String, int). Looking at this method, we see the following code...
So right away I see their algorithm is only looking for a negative sign as a possible first-character position symbol. It appears that they didn't write any code to handle the plus case. Finding this and odd omission, I take my fishing poll and sally forth to the Bug Parade at: http://developer.java.sun.com/developer/bugParade/index.jshtml You have to sign up to access it, but it's free. Doing a search for Integer.parseInt, I find 346 matches. Scanning them, item #6 catches my eye: Bug ID: 4296955 Unary plus not recognized by Integer parsing Looks promising, so I click on it and here's what we find:
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.
Which describes the problem we are having exactly. Scrolling down, we find the Sun engineer's comments:
While it seems somewhat Draconian not to allow a leading plus sign, the specification is clear on this issue, and the implementation obeys the specification. There is code inside the Java platform libraries that would break if we were to change Integer.parseInt's behavior to allow for a leading plus sign (e.g., BigInteger's String constructor), and it is quite likely that we are not unique in this regard. I strongly suspect that our customers also have code that would break if we were to make the suggested incompatible specification change at this late date.
And if we really want to be up to date... How about this link? Now, how do I thread the line through the hook and tie my knots? How do I open the src.jar file? Thank You [ February 15, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
I found this advice: How To Open A Jar But I still can't figure it out.
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
OK, So the Java Archive Tool privided with the SDK will do the job. The basics of its use are described here: Using JAR files: The Basics Anybody know of a free graphics based tool available? This command line stuff causes nightmarish flashbacks of the Days Of DOS.
Thank You [ March 06, 2002: Message edited by: Dirk Schreckmann ]