-
-
Notifications
You must be signed in to change notification settings - Fork 941
Expand file tree
/
Copy pathSafeFloatParser.java
More file actions
60 lines (54 loc) · 1.6 KB
/
SafeFloatParser.java
File metadata and controls
60 lines (54 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.jruby.util;
import java.math.BigDecimal;
/**
* A safer way to parse float values
* <p>
* Prevents brute force attacks using the famous Java bug.
*/
@Deprecated(since = "10.0.3.0")
public final class SafeFloatParser extends SafeDecimalParser {
/**
* Safe way of parsing a Float value from a String
*
* @param s
* The input String
* @return the Float value
*/
@Deprecated(since = "10.0.3.0")
public static Float valueOf(String s) {
return s != null ? Float.valueOf(Double.valueOf(s).floatValue()) : null;
}
/**
* Safe way of parsing a Float value from a String
*
* @param s
* The input String
* @return the Float value
*/
@Deprecated(since = "10.0.3.0")
public static Float parseFloat(String s) {
return s != null ? Float.valueOf(Double.valueOf(s).floatValue()) : null;
}
/**
* Safe way of getting the float value<br>
* prevents BigDecimal from calling Float.parseFloat()
*
* @param number
* @return the float value
*/
@Deprecated(since = "10.0.3.0")
public static float floatValue(Number number) {
return number != null ? (float) number.doubleValue() : 0.0f;
}
/**
* Safe way of getting the float value<br>
* Prevents BigDecimal from calling Float.parseFloat()
*
* @param bigDecimal
* @return the float value
*/
@Deprecated(since = "10.0.3.0")
public static float floatValue(BigDecimal bigDecimal) {
return bigDecimal != null ? (float) bigDecimal.doubleValue() : 0.0f;
}
}