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 BigDecimalLower allowed valueprotected static final BigDecimalThe middle of the bad interval - used for rounding bad valuesprotected static final BigDecimalConstant 2protected static final BigDecimalUpper allowed value -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static final doubledecimalValue(Number number) Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()protected static final doubledecimalValue(BigDecimal bigDecimal) Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()protected static final DoubleSafe parsing of a String into a Doublestatic doubledoubleValue(Number number) Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()static doubledoubleValue(BigDecimal bigDecimal) Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()protected static final booleanHeuristic test if we should look closer at the valuestatic DoubleSafe way of parsing a Double value from a Stringstatic DoubleSafe 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:
trueif the value is suspicious,falseotherwise
-
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
-