Package org.jruby.util
Class SafeFloatParser
java.lang.Object
org.jruby.util.SafeFloatParser
A safer way to parse float 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 floatfloatValue(Number number) Safe way of getting the float value
prevents BigDecimal from calling Float.parseFloat()static floatfloatValue(BigDecimal bigDecimal) Safe way of getting the float value
Prevents BigDecimal from calling Float.parseFloat()protected static final booleanHeuristic test if we should look closer at the valuestatic FloatparseFloat(String s) Safe way of parsing a Float value from a Stringstatic FloatSafe way of parsing a Float 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
-
SafeFloatParser
public SafeFloatParser()
-
-
Method Details
-
valueOf
Safe way of parsing a Float value from a String- Parameters:
s- The input String- Returns:
- the Float value
-
parseFloat
Safe way of parsing a Float value from a String- Parameters:
s- The input String- Returns:
- the Float value
-
floatValue
Safe way of getting the float value
prevents BigDecimal from calling Float.parseFloat()- Parameters:
number-- Returns:
- the float value
-
floatValue
Safe way of getting the float value
Prevents BigDecimal from calling Float.parseFloat()- Parameters:
bigDecimal-- Returns:
- the float 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
-