commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 21904] - NumberUtils.createBigDecimal("") NPE in Sun 1.3.1_08
Date Sat, 26 Jul 2003 15:30:58 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21904>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21904

NumberUtils.createBigDecimal("") NPE in Sun 1.3.1_08





------- Additional Comments From phil@steitz.com  2003-07-26 15:30 -------
I would favor keeping the current contract in place, patching to make things
work in JDK < 1.4.  My understanding of the current contract is

(i)   null |-> null

(ii)  valid representable numeric string |-> value represented

(iii) invalid string |-> NumberFormatException

"" and " " fall under (iii). (Need to add tests for " ".)

One way to achieve this would be to change the guard on the createXxx methods to: 

(4)

  if (str == null) {
      return null;
  }
  if (StringUtils.isBlank(str)) {
      throw new NumberFormatException("A blank string is not a valid Xxx.");
  }  

Or even (following createNumber)

(5)

  if (str == null) {
      return null;
  }
  if (str.length() == 0) {
            throw new NumberFormatException("\"\" is not a valid Xxx.");
  }
 
This should work, but we would have to add tests to verify that " " throws
NumberformatException in all cases, all JDKs when the conversion is attempted.

Phil

---------------------------------------------------------------------
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