Changeset 5776


Ignore:
Timestamp:
Sep 30, 2011, 1:28:05 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1633: NumberFormatException? when parsing NaN values

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Type.java

    r5590 r5776  
    520520    {
    521521      value = value.trim();
     522      if ("NaN".equalsIgnoreCase(value)) return parseString("NaN");
    522523      if (value.indexOf('e') > 0) value = value.replace('e', 'E');
    523524      if (value.indexOf("E+") > 0) value = value.replace("E+", "E");
  • trunk/src/test/TestNumberFormat.java

    r5460 r5776  
    2121*/
    2222import net.sf.basedb.core.Type;
     23import net.sf.basedb.util.EqualsHelper;
    2324import net.sf.basedb.util.NumberFormatUtil;
    2425
     
    7677   
    7778    // Invalid decimal separator
    78     test_parse_number(dotFormat, "123,456", Float.NaN, SHOULD_FAIL);
     79    test_parse_number(dotFormat, "123,456", null, SHOULD_FAIL);
    7980   
    8081    java.text.NumberFormat decFormat = NumberFormatUtil.getNumberFormat(',', ';');
     
    8283    test_parse_number(decFormat, "1,23456E2", resultPositive, SHOULD_PASS);
    8384    test_parse_number(decFormat, "1234,56e-1", resultPositive, SHOULD_PASS);
    84     test_parse_number(decFormat, "123.456", Float.NaN, SHOULD_FAIL);
     85    test_parse_number(decFormat, "123.456", null, SHOULD_FAIL);
    8586
     87    // Special values
     88    test_parse_number(dotFormat, "NaN", null, SHOULD_PASS);
     89   
    8690    write("++Testing Number parser "+(ok ? "OK" : "Failed")+"\n");
    8791    return ok;
     
    9397  }
    9498 
    95   static void test_parse_number(java.text.NumberFormat format, String value, float expectedResult, boolean shouldFail)
     99  static void test_parse_number(java.text.NumberFormat format, String value, Float expectedResult, boolean shouldFail)
    96100  {
    97101    try
     
    102106        throw new Exception("Parsing '" + value + "' should fail; got: " + fValue + "f");
    103107      }
    104       if (fValue != expectedResult)
     108      if (!EqualsHelper.equals(expectedResult, fValue))
    105109      {
    106110        throw new Exception("Parsing '" + value + "' --> " + fValue + "f <> " + expectedResult + " (expected)");
Note: See TracChangeset for help on using the changeset viewer.