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 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 float
floatValue
(Number number) Safe way of getting the float value
prevents BigDecimal from calling Float.parseFloat()static float
floatValue
(BigDecimal bigDecimal) Safe way of getting the float value
Prevents BigDecimal from calling Float.parseFloat()protected static final boolean
Heuristic test if we should look closer at the valuestatic Float
parseFloat
(String s) Safe way of parsing a Float value from a Stringstatic Float
Safe 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:
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
-