From 61e60601c02ff66f87fc04f374804f0b6368a9a6 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 10 Apr 2023 23:28:18 +0200 Subject: [PATCH 1/3] remove problematic-bigint-optimisation --- .../com/fasterxml/jackson/core/io/NumberInput.java | 10 ---------- .../jackson/core/io/BigIntegerParserTest.java | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) 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 1ea1b6b286..e216f48a0f 100644 --- a/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java +++ b/src/main/java/com/fasterxml/jackson/core/io/NumberInput.java @@ -14,13 +14,6 @@ */ public final class NumberInput { - // numbers with more than these characters are better parsed with BigDecimalParser - // parsing numbers with many digits in Java is slower than O(n) - - // 04-Apr-2023, tatu: NOTE! This is above default "longest number by chars" - // limit - private final static int LARGE_INT_SIZE = 1250; - /** * Formerly used constant for a value that was problematic on certain * pre-1.8 JDKs. @@ -496,9 +489,6 @@ public static BigDecimal parseBigDecimal(final char[] ch, final boolean useFastP * @since v2.14 */ public static BigInteger parseBigInteger(final String s) throws NumberFormatException { - if (s.length() > LARGE_INT_SIZE) { - return BigDecimalParser.parse(s).toBigInteger(); - } return new BigInteger(s); } diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java index 95fdcb53ab..2eb9eabbed 100644 --- a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java +++ b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java @@ -1,7 +1,16 @@ package com.fasterxml.jackson.core.io; +import java.math.BigDecimal; +import java.math.BigInteger; + public class BigIntegerParserTest extends com.fasterxml.jackson.core.BaseTest { + public void testFastParseBigIntegerWithENotation() { + String num = "2e308"; + BigInteger bigInteger = BigIntegerParser.parseWithFastParser(num); + assertEquals(new BigDecimal(num).toBigInteger(), bigInteger); + } + public void testLongStringFastParseBigInteger() { try { BigIntegerParser.parseWithFastParser(genLongString()); From edeb3bff5657872be1a38e5794ae248c332c028b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 10 Apr 2023 23:34:41 +0200 Subject: [PATCH 2/3] Update BigIntegerParserTest.java --- .../jackson/core/io/BigIntegerParserTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java index 2eb9eabbed..d63554bb6e 100644 --- a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java +++ b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java @@ -5,10 +5,14 @@ public class BigIntegerParserTest extends com.fasterxml.jackson.core.BaseTest { - public void testFastParseBigIntegerWithENotation() { + public void testFastParseBigIntegerFailsWithENotation() { String num = "2e308"; - BigInteger bigInteger = BigIntegerParser.parseWithFastParser(num); - assertEquals(new BigDecimal(num).toBigInteger(), bigInteger); + try { + BigIntegerParser.parseWithFastParser(num); + fail("expected NumberFormatException"); + } catch (NumberFormatException nfe) { + // expected + } } public void testLongStringFastParseBigInteger() { From fa1c104c4f5a7b55e235eece834d2663685c73ee Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 10 Apr 2023 23:53:17 +0200 Subject: [PATCH 3/3] Update BigIntegerParserTest.java --- .../com/fasterxml/jackson/core/io/BigIntegerParserTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java index d63554bb6e..7b8265d79a 100644 --- a/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java +++ b/src/test/java/com/fasterxml/jackson/core/io/BigIntegerParserTest.java @@ -1,8 +1,5 @@ package com.fasterxml.jackson.core.io; -import java.math.BigDecimal; -import java.math.BigInteger; - public class BigIntegerParserTest extends com.fasterxml.jackson.core.BaseTest { public void testFastParseBigIntegerFailsWithENotation() {