Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.14 only] Backport removal of BigDecimal to BigInt conversion (#987) #990

Merged
merged 2 commits into from
Apr 17, 2023
Merged
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
9 changes: 1 addition & 8 deletions src/main/java/com/fasterxml/jackson/core/io/NumberInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,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)
private final static int LARGE_INT_SIZE = 1250;

/**
* Formerly used constant for a value that was problematic on certain
* pre-1.8 JDKs.
Expand Down Expand Up @@ -398,10 +394,7 @@ public static BigDecimal parseBigDecimal(char[] ch) throws NumberFormatException
* @throws NumberFormatException if string cannot be represented by a BigInteger
* @since v2.14
*/
public static BigInteger parseBigInteger(String s) throws NumberFormatException {
if (s.length() > LARGE_INT_SIZE) {
return BigDecimalParser.parse(s).toBigInteger();
}
public static BigInteger parseBigInteger(final String s) throws NumberFormatException {
return new BigInteger(s);
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/fasterxml/jackson/core/io/TestNumberInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,15 @@ public void testParseLongBigInteger()
String test2000 = stringBuilder.toString();
assertEquals(new BigInteger(test2000), NumberInput.parseBigInteger(test2000));
}

public void testParseBigIntegerFailsWithENotation()
{
try {
NumberInput.parseBigInteger("1e10");
fail("expected NumberFormatException");
} catch (NumberFormatException nfe) {
// expected
}
}
}