Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ public static double parseDouble(final String s) throws NumberFormatException {
* @since v2.14
*/
public static double parseDouble(final String s, final boolean useFastParser) throws NumberFormatException {
return useFastParser ? FastDoubleParser.parseDouble(s) : Double.parseDouble(s);
if (useFastParser) {
try {
return FastDoubleParser.parseDouble(s);
} catch (NumberFormatException ignore) {
return Double.parseDouble(s);
}
}
return Double.parseDouble(s);
}

/**
Expand All @@ -367,7 +374,14 @@ public static float parseFloat(final String s) throws NumberFormatException {
* @since v2.14
*/
public static float parseFloat(final String s, final boolean useFastParser) throws NumberFormatException {
return useFastParser ? FastFloatParser.parseFloat(s) : Float.parseFloat(s);
if (useFastParser) {
try {
return FastFloatParser.parseFloat(s);
} catch (NumberFormatException ignore) {
return Float.parseFloat(s);
}
}
return Float.parseFloat(s);
}

public static BigDecimal parseBigDecimal(String s) throws NumberFormatException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ public void testParseFloat()
assertEquals("1.4E-45", Float.toString(NumberInput.parseFloat(exampleFloat2)));
assertEquals("1.4E-45", Float.toString(NumberInput.parseFloat(exampleFloat2, true)));
}

public void testNastyAcceptedDoubleValues() {
final String[] nastyAcceptedDoubleValues = new String[]{"1.1e-23f", "0x.003p12f", "0x1.17742db862a4P-1d"};

for (String nastyAcceptedDouble : nastyAcceptedDoubleValues) {
assertEquals(Double.parseDouble(nastyAcceptedDouble), NumberInput.parseDouble(nastyAcceptedDouble));
assertEquals(Double.parseDouble(nastyAcceptedDouble), NumberInput.parseDouble(nastyAcceptedDouble, true));
}
}
}