Skip to content

IonParser fails to parse some long values saying they are out of range when they are not #569

@seadbrane

Description

@seadbrane

Some values that are clearly within the range of long fail to be parsed - such as the example below.

com.fasterxml.jackson.core.exc.InputCoercionException: Numeric value (9223372036854775797) out of range of long (-9223372036854775808 - 9223372036854775807)
 at [Source: UNKNOWN; byte offset: #UNKNOWN]
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInputCoercion(ParserMinimalBase.java:618)
	at com.fasterxml.jackson.core.base.ParserMinimalBase.reportOverflowLong(ParserMinimalBase.java:703)
	at com.fasterxml.jackson.core.base.ParserMinimalBase.reportOverflowLong(ParserMinimalBase.java:698)
	at com.fasterxml.jackson.core.base.ParserMinimalBase.reportOverflowLong(ParserMinimalBase.java:693)
	at com.fasterxml.jackson.dataformat.ion.IonParser._getLongValue(IonParser.java:417)
	at com.fasterxml.jackson.dataformat.ion.IonParser.getLongValue(IonParser.java:408)
	at com.fasterxml.jackson.dataformat.ion.IonParserTest.testLongAsBigIntegerSize(IonParserTest.java:50)

The issue is that IonReader returns BIG_INTEGER for getIntegerSize() when it probably shouldn't (working on getting that fixed too). However, the code in _getLongValue() doesn't look correct either, and this can be fixed by checking that the value is in range of BI_MIN_LONG-BI_MAX_LONG instead of BI_MIN_INT-BI_MAX_INT.

if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) {

Here is a test case - although might not want to add it since this should also get fixed upstream.

@Test
    public void testLongAsBigIntegerSize() throws Exception {
        // Note: Values: Long.MAX_VALUE through Long.MAX_VALUE -7 are considered LONG by Ion.  
        BigInteger bigIntLongValue = new BigInteger(Long.MAX_VALUE + "").subtract(new BigInteger("10"));
        IonParser bigIntLongParser = (IonParser) new IonFactory().createParser(bigIntLongValue.toString());
        Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, bigIntLongParser.nextToken());
        Assert.assertEquals(JsonParser.NumberType.BIG_INTEGER, bigIntLongParser.getNumberType());
        Assert.assertEquals(JsonParser.NumberTypeFP.UNKNOWN, bigIntLongParser.getNumberTypeFP());
        Assert.assertEquals(bigIntLongValue.longValue(), bigIntLongParser.getLongValue());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions