2024-05-03 13:52:31 +02:00
|
|
|
From 36ca1db668b34577de7586f5788cd038415ebbfe Mon Sep 17 00:00:00 2001
|
|
|
|
From: Chris Kelley <ckelley@redhat.com>
|
|
|
|
Date: Mon, 19 Jun 2023 21:07:53 +0100
|
|
|
|
Subject: [PATCH] Remove ch.randelshofer.fastdoubleparser
|
|
|
|
|
|
|
|
It is not packaged in Fedora, and it is not enabled by default, so take
|
|
|
|
it out. We can add it back in if we wish to package it later.
|
|
|
|
---
|
|
|
|
.../jackson/core/io/BigDecimalParser.java | 24 ----------
|
|
|
|
.../jackson/core/io/BigIntegerParser.java | 41 -----------------
|
|
|
|
.../jackson/core/io/NumberInput.java | 31 +++----------
|
|
|
|
.../jackson/core/io/BigDecimalParserTest.java | 19 ++------
|
|
|
|
.../jackson/core/io/BigIntegerParserTest.java | 46 -------------------
|
|
|
|
5 files changed, 12 insertions(+), 149 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
|
|
|
|
|
|
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
|
|
|
|
+++ b/src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java
|
|
|
|
@@ -1,7 +1,5 @@
|
|
|
|
package com.fasterxml.jackson.core.io;
|
|
|
|
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaBigDecimalParser;
|
|
|
|
-
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
/**
|
|
|
|
@@ -55,10 +53,7 @@ public final class BigDecimalParser
|
|
|
|
*/
|
|
|
|
public static BigDecimal parse(final char[] chars, final int off, final int len) {
|
|
|
|
try {
|
|
|
|
- if (len < 500) {
|
|
|
|
- return new BigDecimal(chars, off, len);
|
|
|
|
- }
|
|
|
|
- return JavaBigDecimalParser.parseBigDecimal(chars, off, len);
|
|
|
|
+ return new BigDecimal(chars, off, len);
|
|
|
|
|
|
|
|
// 20-Aug-2022, tatu: Although "new BigDecimal(...)" only throws NumberFormatException
|
|
|
|
// operations by "parseBigDecimal()" can throw "ArithmeticException", so handle both:
|
|
|
|
@@ -82,43 +77,6 @@ public final class BigDecimalParser
|
2024-05-03 13:52:31 +02:00
|
|
|
return parse(chars, 0, chars.length);
|
|
|
|
}
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
- /**
|
|
|
|
- * 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
|
|
|
|
- */
|
2024-05-03 13:52:31 +02:00
|
|
|
- public static BigDecimal parseWithFastParser(final String valueStr) {
|
|
|
|
- try {
|
|
|
|
- return JavaBigDecimalParser.parseBigDecimal(valueStr);
|
2024-05-31 14:38:58 +02:00
|
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
|
|
- throw _parseFailure(e, valueStr);
|
2024-05-03 13:52:31 +02:00
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
- /**
|
|
|
|
- * 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
|
|
|
|
- */
|
2024-05-03 13:52:31 +02:00
|
|
|
- public static BigDecimal parseWithFastParser(final char[] ch, final int off, final int len) {
|
|
|
|
- try {
|
|
|
|
- return JavaBigDecimalParser.parseBigDecimal(ch, off, len);
|
2024-05-31 14:38:58 +02:00
|
|
|
- } catch (ArithmeticException | NumberFormatException e) {
|
|
|
|
- throw _parseFailure(e, new String(ch, off, len));
|
2024-05-03 13:52:31 +02:00
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
private static NumberFormatException _parseFailure(Exception e, String fullValue) {
|
|
|
|
String desc = e.getMessage();
|
|
|
|
// 05-Feb-2021, tatu: Alas, JDK mostly has null message so:
|
2024-05-03 13:52:31 +02:00
|
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/BigIntegerParser.java
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1,41 +0,0 @@
|
|
|
|
-package com.fasterxml.jackson.core.io;
|
|
|
|
-
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaBigIntegerParser;
|
|
|
|
-
|
|
|
|
-import java.math.BigInteger;
|
|
|
|
-
|
|
|
|
-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());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
--- a/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
|
|
|
|
+++ b/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
|
|
|
|
@@ -1,8 +1,5 @@
|
|
|
|
package com.fasterxml.jackson.core.io;
|
|
|
|
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaDoubleParser;
|
|
|
|
-import ch.randelshofer.fastdoubleparser.JavaFloatParser;
|
|
|
|
-
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigInteger;
|
2024-05-31 14:38:58 +02:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
@@ -397,7 +394,7 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -422,9 +419,6 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
* @since v2.14
|
|
|
|
*/
|
|
|
|
public static float parseFloat(final String s, final boolean useFastParser) throws NumberFormatException {
|
2024-05-31 14:38:58 +02:00
|
|
|
- if (useFastParser) {
|
|
|
|
- return JavaFloatParser.parseFloat(s);
|
|
|
|
- }
|
|
|
|
return Float.parseFloat(s);
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -448,9 +442,6 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
* @since v2.15
|
|
|
|
*/
|
|
|
|
public static BigDecimal parseBigDecimal(final String s, final boolean useFastParser) throws NumberFormatException {
|
2024-05-31 14:38:58 +02:00
|
|
|
- if (useFastParser) {
|
|
|
|
- return BigDecimalParser.parseWithFastParser(s);
|
|
|
|
- }
|
|
|
|
return BigDecimalParser.parse(s);
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -481,9 +472,6 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
final boolean useFastParser)
|
2024-05-31 14:38:58 +02:00
|
|
|
throws NumberFormatException
|
|
|
|
{
|
|
|
|
- if (useFastParser) {
|
|
|
|
- return BigDecimalParser.parseWithFastParser(ch, off, len);
|
|
|
|
- }
|
|
|
|
return BigDecimalParser.parse(ch, off, len);
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -507,9 +495,7 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
* @since v2.15
|
|
|
|
*/
|
|
|
|
public static BigDecimal parseBigDecimal(final char[] ch, final boolean useFastParser) throws NumberFormatException {
|
|
|
|
- return useFastParser ?
|
|
|
|
- BigDecimalParser.parseWithFastParser(ch, 0, ch.length) :
|
|
|
|
- BigDecimalParser.parse(ch);
|
|
|
|
+ return BigDecimalParser.parse(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -533,9 +519,6 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
* @since v2.15
|
|
|
|
*/
|
|
|
|
public static BigInteger parseBigInteger(final String s, final boolean useFastParser) throws NumberFormatException {
|
|
|
|
- if (useFastParser) {
|
|
|
|
- return BigIntegerParser.parseWithFastParser(s);
|
|
|
|
- }
|
2024-05-31 14:38:58 +02:00
|
|
|
return new BigInteger(s);
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -549,9 +532,6 @@ public final class NumberInput
|
2024-05-03 13:52:31 +02:00
|
|
|
*/
|
|
|
|
public static BigInteger parseBigIntegerWithRadix(final String s, final int radix,
|
2024-05-31 14:38:58 +02:00
|
|
|
final boolean useFastParser) throws NumberFormatException {
|
2024-05-03 13:52:31 +02:00
|
|
|
- if (useFastParser) {
|
|
|
|
- return BigIntegerParser.parseWithFastParser(s, radix);
|
|
|
|
- }
|
2024-05-31 14:38:58 +02:00
|
|
|
return new BigInteger(s, radix);
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
2024-05-31 14:38:58 +02:00
|
|
|
|
2024-05-03 13:52:31 +02:00
|
|
|
--- a/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java
|
|
|
|
+++ b/src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.java
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -10,19 +10,13 @@ class BigDecimalParserTest extends com.f
|
|
|
|
{
|
|
|
|
@Test
|
|
|
|
void longInvalidStringParse() {
|
2024-05-03 13:52:31 +02:00
|
|
|
+ final int len = 1500;
|
|
|
|
+ final StringBuilder sb = new StringBuilder(len);
|
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
|
+ sb.append("A");
|
2024-05-31 14:38:58 +02:00
|
|
|
+ }
|
|
|
|
try {
|
|
|
|
- BigDecimalParser.parse(genLongInvalidString());
|
|
|
|
- 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");
|
|
|
|
- }
|
2024-05-03 13:52:31 +02:00
|
|
|
- }
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
- @Test
|
|
|
|
- void longInvalidStringFastParse() {
|
|
|
|
- try {
|
|
|
|
- BigDecimalParser.parseWithFastParser(genLongInvalidString());
|
2024-05-03 13:52:31 +02:00
|
|
|
+ BigDecimalParser.parse(sb.toString());
|
|
|
|
fail("expected NumberFormatException");
|
|
|
|
} catch (NumberFormatException nfe) {
|
2024-05-31 14:38:58 +02:00
|
|
|
assertTrue(nfe.getMessage().startsWith("Value \"AAAAA"), "exception message starts as expected?");
|
|
|
|
@@ -69,4 +63,7 @@ class BigDecimalParserTest extends com.f
|
|
|
|
sb.append('1');
|
|
|
|
return sb.toString();
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
2024-05-31 14:38:58 +02:00
|
|
|
+ private String genLongString() {
|
|
|
|
+ return BigIntegerParserTest.genLongString();
|
|
|
|
+ }
|
2024-05-03 13:52:31 +02:00
|
|
|
}
|
|
|
|
--- a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java
|
|
|
|
+++ /dev/null
|
2024-05-31 14:38:58 +02:00
|
|
|
@@ -1,54 +0,0 @@
|
2024-05-03 13:52:31 +02:00
|
|
|
-package com.fasterxml.jackson.core.io;
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
|
-
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
2024-05-03 13:52:31 +02:00
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
-class BigIntegerParserTest extends com.fasterxml.jackson.core.JUnit5TestBase {
|
|
|
|
-
|
|
|
|
- @Test
|
|
|
|
- void fastParseBigIntegerFailsWithENotation() {
|
2024-05-03 13:52:31 +02:00
|
|
|
- String num = "2e308";
|
|
|
|
- try {
|
|
|
|
- BigIntegerParser.parseWithFastParser(num);
|
|
|
|
- fail("expected NumberFormatException");
|
|
|
|
- } catch (NumberFormatException nfe) {
|
|
|
|
- // expected
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
- @Test
|
|
|
|
- void longStringFastParseBigInteger() {
|
2024-05-03 13:52:31 +02:00
|
|
|
- try {
|
|
|
|
- BigIntegerParser.parseWithFastParser(genLongString());
|
|
|
|
- fail("expected NumberFormatException");
|
|
|
|
- } catch (NumberFormatException nfe) {
|
2024-05-31 14:38:58 +02:00
|
|
|
- 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");
|
2024-05-03 13:52:31 +02:00
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
2024-05-31 14:38:58 +02:00
|
|
|
- @Test
|
|
|
|
- void longStringFastParseBigIntegerRadix() {
|
2024-05-03 13:52:31 +02:00
|
|
|
- try {
|
|
|
|
- BigIntegerParser.parseWithFastParser(genLongString(), 8);
|
|
|
|
- fail("expected NumberFormatException");
|
|
|
|
- } catch (NumberFormatException nfe) {
|
2024-05-31 14:38:58 +02:00
|
|
|
- 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");
|
2024-05-03 13:52:31 +02:00
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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();
|
|
|
|
- }
|
|
|
|
-}
|