org.jruby.util
Class SafeDoubleParser

java.lang.Object
  extended by org.jruby.util.SafeDoubleParser

public final class SafeDoubleParser
extends java.lang.Object

A safer way to parse double values

Prevents brute force attacks using the famous Java bug.


Field Summary
protected static java.math.BigDecimal LOWER
          Lower allowed value
protected static java.math.BigDecimal MIDDLE
          The middle of the bad interval - used for rounding bad values
protected static java.math.BigDecimal TWO
          Constant 2
protected static java.math.BigDecimal UPPER
          Upper allowed value
 
Constructor Summary
SafeDoubleParser()
           
 
Method Summary
protected static double decimalValue(java.math.BigDecimal bigDecimal)
          Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()
protected static double decimalValue(java.lang.Number number)
          Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()
protected static java.lang.Double decimalValueOf(java.lang.String s)
          Safe parsing of a String into a Double
static double doubleValue(java.math.BigDecimal bigDecimal)
          Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()
static double doubleValue(java.lang.Number number)
          Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()
protected static boolean isSuspicious(java.lang.String s)
          Heuristic test if we should look closer at the value
static java.lang.Double parseDouble(java.lang.String s)
          Safe way of parsing a Double value from a String
static java.lang.Double valueOf(java.lang.String s)
          Safe way of parsing a Double value from a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TWO

protected static final java.math.BigDecimal TWO
Constant 2


LOWER

protected static final java.math.BigDecimal LOWER
Lower allowed value


UPPER

protected static final java.math.BigDecimal UPPER
Upper allowed value


MIDDLE

protected static final java.math.BigDecimal MIDDLE
The middle of the bad interval - used for rounding bad values

Constructor Detail

SafeDoubleParser

public SafeDoubleParser()
Method Detail

valueOf

public static java.lang.Double valueOf(java.lang.String s)
Safe way of parsing a Double value from a String

Parameters:
s - The input String
Returns:
the Double value

parseDouble

public static java.lang.Double parseDouble(java.lang.String s)
Safe way of parsing a Double value from a String

Parameters:
s - The input String
Returns:
the Double value

doubleValue

public static double doubleValue(java.lang.Number number)
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()

Parameters:
number -
Returns:
the double value

doubleValue

public static double doubleValue(java.math.BigDecimal bigDecimal)
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()

Parameters:
bigDecimal -
Returns:
the double value

isSuspicious

protected static final boolean isSuspicious(java.lang.String s)
Heuristic test if we should look closer at the value

Parameters:
s - The non-null input String
Returns:
true if the value is suspicious, false otherwise

decimalValueOf

protected static final java.lang.Double decimalValueOf(java.lang.String s)
Safe parsing of a String into a Double

Parameters:
s - The input String, can be null
Returns:
The Double value

decimalValue

protected static final double decimalValue(java.lang.Number number)
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()

Parameters:
number -
Returns:
the double value

decimalValue

protected static final double decimalValue(java.math.BigDecimal bigDecimal)
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()

Parameters:
bigDecimal -
Returns:
the double value


Copyright © 2002-2009 JRuby Team. All Rights Reserved.