416 lines
17 KiB
Diff
416 lines
17 KiB
Diff
From ddc1f5588ca7634e5a8aab30cfdb8ce3eb06d360 Mon Sep 17 00:00:00 2001
|
|
From: Marco Fargetta <mfargett@redhat.com>
|
|
Date: Tue, 15 Jul 2025 18:03:33 +0200
|
|
Subject: [PATCH] Remove ch.randelshofer.fastdoubleparser library
|
|
|
|
---
|
|
.../jackson/core/io/BigDecimalParser.java | 59 ++-----------------
|
|
.../jackson/core/io/BigIntegerParser.java | 41 -------------
|
|
.../jackson/core/io/NumberInput.java | 29 +--------
|
|
.../jackson/core/io/BigDecimalParserTest.java | 11 ++--
|
|
.../jackson/core/io/BigIntegerParserTest.java | 54 -----------------
|
|
.../core/io/doubleparser/ReaderTest.java | 42 -------------
|
|
6 files changed, 12 insertions(+), 224 deletions(-)
|
|
delete mode 100644 src/main/java/com/fasterxml/jackson/core/io/BigIntegerParser.java
|
|
delete mode 100644 src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java
|
|
delete mode 100644 src/test/java/com/fasterxml/jackson/core/io/doubleparser/ReaderTest.java
|
|
|
|
diff --git a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
|
|
index 913c4ce7..d4b8ee2e 100644
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
|
|
+++ b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
|
|
@@ -2,8 +2,6 @@ package com.fasterxml.jackson.core.io;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaBigDecimalParser;
|
|
-
|
|
/**
|
|
* Internal Jackson Helper class used to implement more optimized parsing of {@link BigDecimal} for REALLY
|
|
* big values (over 500 characters).
|
|
@@ -42,14 +40,8 @@ public final class BigDecimalParser
|
|
*/
|
|
public static BigDecimal parse(String valueStr) {
|
|
try {
|
|
- if (valueStr.length() < SIZE_FOR_SWITCH_TO_FASTDOUBLEPARSER) {
|
|
- return new BigDecimal(valueStr);
|
|
- }
|
|
- return JavaBigDecimalParser.parseBigDecimal(valueStr);
|
|
-
|
|
- // 20-Aug-2022, tatu: Although "new BigDecimal(...)" only throws NumberFormatException
|
|
- // operations by "parseBigDecimal()" can throw "ArithmeticException", so handle both:
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
+ return new BigDecimal(valueStr);
|
|
+ } catch (NumberFormatException e) {
|
|
throw _parseFailure(e, valueStr);
|
|
}
|
|
}
|
|
@@ -66,14 +58,8 @@ public final class BigDecimalParser
|
|
*/
|
|
public static BigDecimal parse(final char[] chars, final int off, final int len) {
|
|
try {
|
|
- if (len < SIZE_FOR_SWITCH_TO_FASTDOUBLEPARSER) {
|
|
- return new BigDecimal(chars, off, len);
|
|
- }
|
|
- return JavaBigDecimalParser.parseBigDecimal(chars, off, len);
|
|
-
|
|
- // 20-Aug-2022, tatu: Although "new BigDecimal(...)" only throws NumberFormatException
|
|
- // operations by "parseBigDecimal()" can throw "ArithmeticException", so handle both:
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
+ return new BigDecimal(chars, off, len);
|
|
+ } catch (NumberFormatException e) {
|
|
throw _parseFailure(e, chars, off, len);
|
|
}
|
|
}
|
|
@@ -93,43 +79,6 @@ public final class BigDecimalParser
|
|
return parse(chars, 0, chars.length);
|
|
}
|
|
|
|
- /**
|
|
- * Internal Jackson method. Please do not use.
|
|
- *<p>
|
|
- * Note: Caller MUST pre-validate that given String represents a valid representation
|
|
- * of {@link BigDecimal} value: parsers in {@code jackson-core} do that; other
|
|
- * code must do the same.
|
|
- *
|
|
- * @param valueStr
|
|
- * @return BigDecimal value
|
|
- * @throws NumberFormatException
|
|
- */
|
|
- public static BigDecimal parseWithFastParser(final String valueStr) {
|
|
- try {
|
|
- return JavaBigDecimalParser.parseBigDecimal(valueStr);
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
- throw _parseFailure(e, valueStr);
|
|
- }
|
|
- }
|
|
-
|
|
- /**
|
|
- * Internal Jackson method. Please do not use.
|
|
- *<p>
|
|
- * Note: Caller MUST pre-validate that given String represents a valid representation
|
|
- * of {@link BigDecimal} value: parsers in {@code jackson-core} do that; other
|
|
- * code must do the same.
|
|
- *
|
|
- * @return BigDecimal value
|
|
- * @throws NumberFormatException
|
|
- */
|
|
- public static BigDecimal parseWithFastParser(final char[] ch, final int off, final int len) {
|
|
- try {
|
|
- return JavaBigDecimalParser.parseBigDecimal(ch, off, len);
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
- throw _parseFailure(e, ch, off, len);
|
|
- }
|
|
- }
|
|
-
|
|
private static NumberFormatException _parseFailure(Exception e, String fullValue) {
|
|
String desc = e.getMessage();
|
|
// 05-Feb-2021, tatu: Alas, JDK mostly has null message so:
|
|
diff --git a/src/main/java/com/fasterxml/jackson/core/io/BigIntegerParser.java b/src/main/java/com/fasterxml/jackson/core/io/BigIntegerParser.java
|
|
deleted file mode 100644
|
|
index be61ef1b..00000000
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/BigIntegerParser.java
|
|
+++ /dev/null
|
|
@@ -1,41 +0,0 @@
|
|
-package com.fasterxml.jackson.core.io;
|
|
-
|
|
-import java.math.BigInteger;
|
|
-
|
|
-import ch.randelshofer.fastdoubleparser.JavaBigIntegerParser;
|
|
-
|
|
-import static com.fasterxml.jackson.core.io.BigDecimalParser.MAX_CHARS_TO_REPORT;
|
|
-
|
|
-/**
|
|
- * Helper class used to implement more optimized parsing of {@link BigInteger} for REALLY
|
|
- * big values (over 500 characters).
|
|
- *
|
|
- * @since 2.15
|
|
- */
|
|
-public final class BigIntegerParser
|
|
-{
|
|
- private BigIntegerParser() {}
|
|
-
|
|
- public static BigInteger parseWithFastParser(final String valueStr) {
|
|
- try {
|
|
- return JavaBigIntegerParser.parseBigInteger(valueStr);
|
|
- } catch (NumberFormatException nfe) {
|
|
- final String reportNum = valueStr.length() <= MAX_CHARS_TO_REPORT ?
|
|
- valueStr : valueStr.substring(0, MAX_CHARS_TO_REPORT) + " [truncated]";
|
|
- throw new NumberFormatException("Value \"" + reportNum
|
|
- + "\" can not be represented as `java.math.BigInteger`, reason: " + nfe.getMessage());
|
|
- }
|
|
- }
|
|
-
|
|
- public static BigInteger parseWithFastParser(final String valueStr, final int radix) {
|
|
- try {
|
|
- return JavaBigIntegerParser.parseBigInteger(valueStr, radix);
|
|
- } catch (NumberFormatException nfe) {
|
|
- final String reportNum = valueStr.length() <= MAX_CHARS_TO_REPORT ?
|
|
- valueStr : valueStr.substring(0, MAX_CHARS_TO_REPORT) + " [truncated]";
|
|
- throw new NumberFormatException("Value \"" + reportNum
|
|
- + "\" can not be represented as `java.math.BigInteger` with radix " + radix +
|
|
- ", reason: " + nfe.getMessage());
|
|
- }
|
|
- }
|
|
-}
|
|
diff --git a/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java b/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
|
|
index 9656294d..4db891ea 100644
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
|
|
+++ b/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
|
|
@@ -4,9 +4,6 @@ import java.math.BigDecimal;
|
|
import java.math.BigInteger;
|
|
import java.util.regex.Pattern;
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaDoubleParser;
|
|
-import ch.randelshofer.fastdoubleparser.JavaFloatParser;
|
|
-
|
|
/**
|
|
* Helper class for efficient parsing of various JSON numbers.
|
|
*<p>
|
|
@@ -407,7 +404,7 @@ public final class NumberInput
|
|
* @since v2.14
|
|
*/
|
|
public static double parseDouble(final String s, final boolean useFastParser) throws NumberFormatException {
|
|
- return useFastParser ? JavaDoubleParser.parseDouble(s) : Double.parseDouble(s);
|
|
+ return Double.parseDouble(s);
|
|
}
|
|
|
|
/**
|
|
@@ -432,8 +429,7 @@ public final class NumberInput
|
|
*/
|
|
public static double parseDouble(final char[] array, final int offset,
|
|
final int len, final boolean useFastParser) throws NumberFormatException {
|
|
- return useFastParser ? JavaDoubleParser.parseDouble(array, offset, len) :
|
|
- Double.parseDouble(new String(array, offset, len));
|
|
+ return Double.parseDouble(new String(array, offset, len));
|
|
}
|
|
|
|
/**
|
|
@@ -458,9 +454,6 @@ public final class NumberInput
|
|
* @since v2.14
|
|
*/
|
|
public static float parseFloat(final String s, final boolean useFastParser) throws NumberFormatException {
|
|
- if (useFastParser) {
|
|
- return JavaFloatParser.parseFloat(s);
|
|
- }
|
|
return Float.parseFloat(s);
|
|
}
|
|
|
|
@@ -486,8 +479,7 @@ public final class NumberInput
|
|
*/
|
|
public static float parseFloat(final char[] array, final int offset,
|
|
final int len, final boolean useFastParser) throws NumberFormatException {
|
|
- return useFastParser ? JavaFloatParser.parseFloat(array, offset, len) :
|
|
- Float.parseFloat(new String(array, offset, len));
|
|
+ return Float.parseFloat(new String(array, offset, len));
|
|
}
|
|
|
|
/**
|
|
@@ -510,9 +502,6 @@ public final class NumberInput
|
|
* @since v2.15
|
|
*/
|
|
public static BigDecimal parseBigDecimal(final String s, final boolean useFastParser) throws NumberFormatException {
|
|
- if (useFastParser) {
|
|
- return BigDecimalParser.parseWithFastParser(s);
|
|
- }
|
|
return BigDecimalParser.parse(s);
|
|
}
|
|
|
|
@@ -543,9 +532,6 @@ public final class NumberInput
|
|
final boolean useFastParser)
|
|
throws NumberFormatException
|
|
{
|
|
- if (useFastParser) {
|
|
- return BigDecimalParser.parseWithFastParser(ch, off, len);
|
|
- }
|
|
return BigDecimalParser.parse(ch, off, len);
|
|
}
|
|
|
|
@@ -569,9 +555,6 @@ public final class NumberInput
|
|
* @since v2.15
|
|
*/
|
|
public static BigDecimal parseBigDecimal(final char[] ch, final boolean useFastParser) throws NumberFormatException {
|
|
- if (useFastParser) {
|
|
- return BigDecimalParser.parseWithFastParser(ch, 0, ch.length);
|
|
- }
|
|
return BigDecimalParser.parse(ch);
|
|
}
|
|
|
|
@@ -596,9 +579,6 @@ public final class NumberInput
|
|
* @since v2.15
|
|
*/
|
|
public static BigInteger parseBigInteger(final String s, final boolean useFastParser) throws NumberFormatException {
|
|
- if (useFastParser) {
|
|
- return BigIntegerParser.parseWithFastParser(s);
|
|
- }
|
|
return new BigInteger(s);
|
|
}
|
|
|
|
@@ -612,9 +592,6 @@ public final class NumberInput
|
|
*/
|
|
public static BigInteger parseBigIntegerWithRadix(final String s, final int radix,
|
|
final boolean useFastParser) throws NumberFormatException {
|
|
- if (useFastParser) {
|
|
- return BigIntegerParser.parseWithFastParser(s, radix);
|
|
- }
|
|
return new BigInteger(s, radix);
|
|
}
|
|
|
|
diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java
|
|
index 9ec4cc6c..b067bad0 100644
|
|
--- a/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java
|
|
+++ b/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java
|
|
@@ -2,7 +2,6 @@ package com.fasterxml.jackson.core.io;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaBigDecimalParser;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
@@ -23,7 +22,7 @@ class BigDecimalParserTest extends com.fasterxml.jackson.core.JUnit5TestBase
|
|
@Test
|
|
void longInvalidStringFastParse() {
|
|
try {
|
|
- BigDecimalParser.parseWithFastParser(genLongInvalidString());
|
|
+ BigDecimalParser.parse(genLongInvalidString());
|
|
fail("expected NumberFormatException");
|
|
} catch (NumberFormatException nfe) {
|
|
assertTrue(nfe.getMessage().startsWith("Value \"AAAAA"), "exception message starts as expected?");
|
|
@@ -48,8 +47,8 @@ class BigDecimalParserTest extends com.fasterxml.jackson.core.JUnit5TestBase
|
|
final BigDecimal EXP = new BigDecimal(num);
|
|
|
|
// Parse from String first, then char[]
|
|
- assertEquals(EXP, BigDecimalParser.parseWithFastParser(num));
|
|
- assertEquals(EXP, BigDecimalParser.parseWithFastParser(num.toCharArray(), 0, num.length()));
|
|
+ assertEquals(EXP, BigDecimalParser.parse(num));
|
|
+ assertEquals(EXP, BigDecimalParser.parse(num.toCharArray(), 0, num.length()));
|
|
}
|
|
|
|
@Test
|
|
@@ -58,10 +57,10 @@ class BigDecimalParserTest extends com.fasterxml.jackson.core.JUnit5TestBase
|
|
final BigDecimal expected = new BigDecimal(str);
|
|
assertEquals(expected, JavaBigDecimalParser.parseBigDecimal(str));
|
|
assertEquals(expected, BigDecimalParser.parse(str));
|
|
- assertEquals(expected, BigDecimalParser.parseWithFastParser(str));
|
|
+ assertEquals(expected, BigDecimalParser.parse(str));
|
|
final char[] arr = str.toCharArray();
|
|
assertEquals(expected, BigDecimalParser.parse(arr, 0, arr.length));
|
|
- assertEquals(expected, BigDecimalParser.parseWithFastParser(arr, 0, arr.length));
|
|
+ assertEquals(expected, BigDecimalParser.parse(arr, 0, arr.length));
|
|
}
|
|
|
|
static String genLongInvalidString() {
|
|
diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java
|
|
deleted file mode 100644
|
|
index a515f656..00000000
|
|
--- a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java
|
|
+++ /dev/null
|
|
@@ -1,54 +0,0 @@
|
|
-package com.fasterxml.jackson.core.io;
|
|
-
|
|
-import org.junit.jupiter.api.Test;
|
|
-
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
-
|
|
-class BigIntegerParserTest extends com.fasterxml.jackson.core.JUnit5TestBase {
|
|
-
|
|
- @Test
|
|
- void fastParseBigIntegerFailsWithENotation() {
|
|
- String num = "2e308";
|
|
- try {
|
|
- BigIntegerParser.parseWithFastParser(num);
|
|
- fail("expected NumberFormatException");
|
|
- } catch (NumberFormatException nfe) {
|
|
- // expected
|
|
- }
|
|
- }
|
|
-
|
|
- @Test
|
|
- void longStringFastParseBigInteger() {
|
|
- try {
|
|
- BigIntegerParser.parseWithFastParser(genLongString());
|
|
- fail("expected NumberFormatException");
|
|
- } catch (NumberFormatException nfe) {
|
|
- assertTrue(nfe.getMessage().startsWith("Value \"AAAAA"), "exception message starts as expected?");
|
|
- assertTrue(nfe.getMessage().contains("truncated"), "exception message value contains: truncated");
|
|
- assertTrue(nfe.getMessage().contains("BigInteger"), "exception message value contains: BigInteger");
|
|
- }
|
|
- }
|
|
-
|
|
- @Test
|
|
- void longStringFastParseBigIntegerRadix() {
|
|
- try {
|
|
- BigIntegerParser.parseWithFastParser(genLongString(), 8);
|
|
- fail("expected NumberFormatException");
|
|
- } catch (NumberFormatException nfe) {
|
|
- assertTrue(nfe.getMessage().startsWith("Value \"AAAAA"), "exception message starts as expected?");
|
|
- assertTrue(nfe.getMessage().contains("truncated"), "exception message value contains: truncated");
|
|
- assertTrue(nfe.getMessage().contains("radix 8"), "exception message value contains: radix 8");
|
|
- assertTrue(nfe.getMessage().contains("BigInteger"), "exception message value contains: BigInteger");
|
|
- }
|
|
- }
|
|
-
|
|
- static String genLongString() {
|
|
- final int len = 1500;
|
|
- final StringBuilder sb = new StringBuilder(len);
|
|
- for (int i = 0; i < len; i++) {
|
|
- sb.append("A");
|
|
- }
|
|
- return sb.toString();
|
|
- }
|
|
-}
|
|
diff --git a/src/test/java/com/fasterxml/jackson/core/io/doubleparser/ReaderTest.java b/src/test/java/com/fasterxml/jackson/core/io/doubleparser/ReaderTest.java
|
|
deleted file mode 100644
|
|
index 4b56b9f0..00000000
|
|
--- a/src/test/java/com/fasterxml/jackson/core/io/doubleparser/ReaderTest.java
|
|
+++ /dev/null
|
|
@@ -1,42 +0,0 @@
|
|
-package com.fasterxml.jackson.core.io.doubleparser;
|
|
-
|
|
-import java.util.Random;
|
|
-
|
|
-import ch.randelshofer.fastdoubleparser.JavaDoubleParser;
|
|
-import ch.randelshofer.fastdoubleparser.JavaFloatParser;
|
|
-import org.junit.jupiter.api.Test;
|
|
-
|
|
-import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
-
|
|
-class ReaderTest {
|
|
- private static final int LEN = 1000;
|
|
- private static final String[] DOUBLE_STRINGS = new String[LEN];
|
|
- private static final String[] FLOAT_STRINGS = new String[LEN];
|
|
-
|
|
- static {
|
|
- Random rnd = new Random();
|
|
- for (int i = 0; i < LEN; i++) {
|
|
- DOUBLE_STRINGS[i] = Double.toString(rnd.nextDouble());
|
|
- FLOAT_STRINGS[i] = Float.toString(rnd.nextFloat());
|
|
- }
|
|
- }
|
|
-
|
|
- @Test
|
|
- void verifyDoubles() {
|
|
- for (int i = 0; i < LEN; i++) {
|
|
- double fd = JavaDoubleParser.parseDouble(DOUBLE_STRINGS[i]);
|
|
- double jd = Double.parseDouble(DOUBLE_STRINGS[i]);
|
|
- assertEquals(jd, fd);
|
|
- }
|
|
- }
|
|
-
|
|
- @Test
|
|
- void verifyFloats() {
|
|
- for (int i = 0; i < LEN; i++) {
|
|
- float ff = JavaFloatParser.parseFloat(FLOAT_STRINGS[i]);
|
|
- float jf = Float.parseFloat(FLOAT_STRINGS[i]);
|
|
- assertEquals(jf, ff);
|
|
- }
|
|
- }
|
|
-
|
|
-}
|
|
\ No newline at end of file
|
|
--
|
|
2.50.1
|
|
|