Package org.jruby.util
Class SafeDoubleParser
java.lang.Object
org.jruby.util.SafeDoubleParser
A safer way to parse double values
Prevents brute force attacks using the famous Java bug.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimal
Lower allowed valueprotected static final BigDecimal
The middle of the bad interval - used for rounding bad valuesprotected static final BigDecimal
Constant 2protected static final BigDecimal
Upper allowed value -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static final double
decimalValue
(Number number) Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()protected static final double
decimalValue
(BigDecimal bigDecimal) Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()protected static final Double
Safe parsing of a String into a Doublestatic double
doubleValue
(Number number) Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()static double
doubleValue
(BigDecimal bigDecimal) Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()protected static final boolean
Heuristic test if we should look closer at the valuestatic Double
Safe way of parsing a Double value from a Stringstatic Double
Safe way of parsing a Double value from a String
-
Field Details
-
TWO
Constant 2 -
LOWER
Lower allowed value -
UPPER
Upper allowed value -
MIDDLE
The middle of the bad interval - used for rounding bad values
-
-
Constructor Details
-
SafeDoubleParser
public SafeDoubleParser()
-
-
Method Details
-
valueOf
Safe way of parsing a Double value from a String- Parameters:
s
- The input String- Returns:
- the Double value
-
parseDouble
Safe way of parsing a Double value from a String- Parameters:
s
- The input String- Returns:
- the Double value
-
doubleValue
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()- Parameters:
number
-- Returns:
- the double value
-
doubleValue
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()- Parameters:
bigDecimal
-- Returns:
- the double value
-
isSuspicious
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
Safe parsing of a String into a Double- Parameters:
s
- The input String, can be null- Returns:
- The Double value
-
decimalValue
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()- Parameters:
number
-- Returns:
- the double value
-
decimalValue
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()- Parameters:
bigDecimal
-- Returns:
- the double value
-