Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
Operating System: other
Platform: Other
-
21904
Description
Hello,
The NumberUtils.createXXX methods all have the following pattern:
public static XXX createXXX(String str) {
if (str == 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