commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] createInteger with leading 0's fails.
Date Mon, 10 Mar 2003 23:39:11 GMT
How does this conflict with the use of a leading zero to indicate base-8?

If not then I think it could be a worthwhile addition.

Stephen

----- Original Message -----
From: <EPugh@upstate.com>
To: <commons-dev@jakarta.apache.org>
Sent: Monday, March 10, 2003 7:43 PM
Subject: [lang] createInteger with leading 0's fails.


> Hi all,
>
> I added this testcase to NumberUtilsTest.java:
>
> public void testCreateIntegerLeadingZero() {
>         assertEquals("createInteger2(String) failed", new Integer("8"),
> NumberUtils.createInteger("08"));
>     }
>
> and I get the expected:
> Testcase: testCreateInteger2 took 0 sec
> Caused an ERROR
> 8
> java.lang.NumberFormatException: 8
> at java.lang.Integer.parseInt(Integer.java:414)
> at java.lang.Integer.valueOf(Integer.java:491)
> at java.lang.Integer.decode(Integer.java:835)
> at
> org.apache.commons.lang.NumberUtils.createInteger(NumberUtils.java:363)
>
> In my code, users sometimes enter 01 as meaning 1.  This means I have this
> hokey StringUtils.strip(mystring,"0") before I hit the createInteger
> function.  However, on thinking, is this a bug with the NumberUtils code?
> If so, I volunteer to submit a patch for this.  Just looking for some
> guidence before I make the changes.
>
> Eric Pugh
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message