Changeset 3590


Ignore:
Timestamp:
Jul 23, 2007, 12:43:11 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #688: Don't use Float.valueOf() or Float.parseString() to parse integer values

Location:
trunk/src/core/net/sf/basedb
Files:
6 edited

Legend:

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

    r3562 r3590  
    196196    Numeric properties are parsed with the specified number format.
    197197    @param value The value to parse
    198     @param numberFormat The number format, or null to use Float.valueOf or Double.valueOf
     198    @param numberFormat The number format, or null to use Double.valueOf
    199199    @return An object
    200200    @throws InvalidDataException If the string cannot be converted to the correct type
     
    214214    parsed. Otherwise an exception is thrown.
    215215    @param value The value to parse
    216     @param numberFormat The number format, or null to use Float.valueOf or Double.valueOf
     216    @param numberFormat The number format, or null to use Double.valueOf
    217217    @param nullIfException TRUE to return null in case the string can't be parsed,
    218218      FALSE to throw an exception
  • trunk/src/core/net/sf/basedb/core/Type.java

    r3472 r3590  
    7070    {
    7171      if (value == null) return null;
    72       return new Integer(Float.valueOf(value).intValue());
     72      return new Integer(Double.valueOf(value).intValue());
    7373    }
    7474    public Number convertNumber(Number num)
     
    9494      throws InvalidDataException
    9595    {
    96       return new Long(Float.valueOf(value).intValue());
     96      return new Long(Double.valueOf(value).intValue());
    9797    }
    9898    public Number convertNumber(Number num)
  • trunk/src/core/net/sf/basedb/util/Values.java

    r3190 r3590  
    6565    if (value != null)
    6666    {
    67       try { return Float.valueOf(value).intValue(); }
     67      try { return Double.valueOf(value).intValue(); }
    6868      catch (Throwable t) {}
    6969    }
     
    7575    if (value != null)
    7676    {
    77       try { return Float.valueOf(value).intValue(); }
     77      try { return Double.valueOf(value).intValue(); }
    7878      catch (Throwable t) {}
    7979    }
  • trunk/src/core/net/sf/basedb/util/parser/ColumnMapper.java

    r3472 r3590  
    7575    @param nullIfException If TRUE, the mapper returns null for unparsable numeric
    7676      values, otherwise an excption is thrown
    77     @param parser The parser to use or null to use Float.valueOf()
     77    @param parser The parser to use or null to use Double.valueOf()
    7878    @since 2.4
    7979  */
     
    102102  public Integer getInt(Data data)
    103103  {
    104     return getFloat(getValue(data)).intValue();
     104    Double d = getDouble(getValue(data));
     105    return d == null ? null : d.intValue();
    105106  }
    106107  public Float getFloat(Data data)
    107108  {
    108     return getFloat(getValue(data));
     109    Double d = getDouble(getValue(data));
     110    return d == null ? null : d.floatValue();
    109111  }
    110112  // -------------------------------------------
     
    120122  // -------------------------------------------
    121123 
    122   private Float getFloat(String value)
     124  private Double getDouble(String value)
    123125  {
    124126    if (value == null) return null;
    125     Float f = null;
     127    Double d = null;
    126128    if (parser == null)
    127129    {
    128130      try
    129131      {
    130         f = Float.valueOf(value);
     132        d = Double.valueOf(value);
    131133      }
    132134      catch (RuntimeException rex)
     
    137139    else
    138140    {
    139       f = (Float)Type.FLOAT.parseString(value, parser, nullIfException);
     141      d = (Double)Type.DOUBLE.parseString(value, parser, nullIfException);
    140142    }
    141     return f;
     143    return d;
    142144  }
    143145 
  • trunk/src/core/net/sf/basedb/util/parser/CompoundMapper.java

    r3472 r3590  
    117117        try
    118118        {
    119           intValue = Integer.parseInt(stringValue);
     119          intValue = Double.valueOf(stringValue).intValue();
    120120        }
    121121        catch (RuntimeException rex)
  • trunk/src/core/net/sf/basedb/util/parser/ConstantMapper.java

    r3472 r3590  
    5959    Create a constant mapper using a specific number formatter as it's parser.
    6060    @param constant The constant expression
    61     @param parser The number format to use or null to use Float.valueOf()
     61    @param parser The number format to use or null to use Double.valueOf()
    6262    @since 2.2
    6363    @deprecated Use {@link ConstantMapper#ConstantMapper(String, NumberFormat, boolean)}
     
    7171    Create a constant mapper using a specific number formatter as it's parser.
    7272    @param constant The constant expression
    73     @param parser The number format to use or null to use Float.valueOf()
     73    @param parser The number format to use or null to use Double.valueOf()
    7474    @param nullIfException If TRUE, the mapper returns null for unparsable numeric
    7575      values, otherwise an excption is thrown
     
    151151      else
    152152      {
    153         asFloat = Float.valueOf(constant);
     153        asFloat = Double.valueOf(constant).floatValue();
    154154      }
    155155    }
Note: See TracChangeset for help on using the changeset viewer.