commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EP...@upstate.com
Subject [lang] createInteger with leading 0's fails.
Date Mon, 10 Mar 2003 19:43:33 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message