You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <gg...@seagullsw.com> on 2003/07/26 05:18:09 UTC

RE: [lang] NumberUtilsNumberUtils.createXXX methods and empty str ings [WAS: unit tests 1.3.1_08 vs 1.4.2.]

FYI, tracking here: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21904

Gary

-----Original Message-----
From: Gary Gregory [mailto:ggregory@seagullsw.com] 
Sent: Friday, July 25, 2003 19:52
To: 'Jakarta Commons Developers List'
Subject: [lang] NumberUtilsNumberUtils.createXXX methods and empty strings
[WAS: unit tests 1.3.1_08 vs 1.4.2.]

Hello,

The NumberUtils.createXXX methods all have the following pattern:

public static XXX createXXX(String str) {
   if (str == null) {
      return null;
   }

In the case of BigDecimal, passing in a "" to new BigDecimal(String) in Sun
1.3.1_08 blows up like this:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:582)
	at java.math.BigDecimal.<init>(BigDecimal.java:124)
	at
org.apache.commons.lang.math.NumberUtils.createBigDecimal(NumberUtils.java:4
78)
	at
org.apache.commons.lang.math.NumberUtilsTest.testCreateBigDecimal(NumberUtil
sTest.java:209)

Under Sun 1.4.2, you get a NumberFormatException if the length of the string
is 0 (no trim()). The unit tests expect a NumberFormatException when you
pass in "".

So... to make this all nice on 1.3, should all of the guard clauses become:

(1)

   if (StringUtil.isEmpty(str)) {
      return null;
   }

(2)

   if (StringUtil.isBlank(str)) {
      return null;
   }

(3)

   if (str == null) {
      return null;
   }
   if (StringUtil.isEmpty(str)) {
      return str;
   }
?

I think (2) would be good since it would not blow up on "" AND " " but I am
not familiar with the various invocation contexts, so, please opine.

Thanks,
Gary

-----Original Message-----
From: Gary Gregory [mailto:ggregory@seagullsw.com] 
Sent: Friday, July 25, 2003 17:53
To: 'Jakarta Commons Developers List'
Subject: [lang] unit tests 1.3.1_08 vs 1.4.2.

I am seing something odd: under Sun 1.4.2, the unit tests run fine but under
Sun 1.3.1_08, they do not. Specifically:

test.lang:
     [echo] Running lang package tests ...
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................F................
     [java] ...............................
     [java] Time: 0.285
     [java] There was 1 failure:
     [java] 1)
testIndexOf_StringInt(org.apache.commons.lang.StringUtilsEqualsIndexOfTest)j
unit.framework.AssertionFailedError: expected:<0> but was:<-1>
     [java]     at
org.apache.commons.lang.StringUtilsEqualsIndexOfTest.testIndexOf_StringInt(S
tringUtilsEqualsIndexOfTest.java:158)

     [java] FAILURES!!!
     [java] Tests run: 359,  Failures: 1,  Errors: 0


and:


test.math:
     [echo] Running math package tests ...
     [java] .........................................
     [java] .........................................
     [java] ..................................E.......
     [java] ..........................
     [java] Time: 9.424
     [java] There was 1 error:
     [java] 1)
testCreateBigDecimal(org.apache.commons.lang.math.NumberUtilsTest)java.lang.
StringIndexOutOfBoundsException: String index out of range: 0
     [java]     at java.lang.String.charAt(String.java:582)
     [java]     at java.math.BigDecimal.<init>(BigDecimal.java:124)
     [java]     at
org.apache.commons.lang.math.NumberUtils.createBigDecimal(NumberUtils.java:4
78)
     [java]     at
org.apache.commons.lang.math.NumberUtilsTest.testCreateBigDecimal(NumberUtil
sTest.java:209)

     [java] FAILURES!!!
     [java] Tests run: 149,  Failures: 0,  Errors: 1

Gary

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Friday, July 25, 2003 16:12
To: Jakarta Commons Developers List
Subject: Re: [lang] Findbugs output for Lang 2.0

I've addressed these as seems sensible.

Some static variables went from protected to private
Some static variables went from non-final to final

Stephen

----- Original Message ----- 
From: "Henri Yandell" <ba...@generationjava.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, July 23, 2003 9:54 PM
Subject: [lang] Findbugs output for Lang 2.0


> 
> Taking current CVS I get the following as output from the Findbugs
> project.
> 
> Lang output: http://www.flamefew.net/~hen/lang-2.0-findbugs-output.html
> Findbugs:    http://www.cs.umd.edu/~pugh/java/bugs/
> 
> 
> Just in case anyone's interested :)
> 
> Hen
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


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