Skip to content

Commit

Permalink
[2.14 only] backport removal of BigDecimal to BigInt conversion (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Apr 17, 2023
1 parent e77e28e commit a4f2086
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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
}
}
}

0 comments on commit a4f2086

Please sign in to comment.