Skip to content

Integer bounds verification when calling TokenBuffer.getIntValue() #1729

Closed
@newkek

Description

@newkek

Hello,

Using the TokenBuffer API I have noticed some unexpected behaviour wrt to 32 bit integers limits when deserializing a constructed TokenBuffer. It seems like when calling getIntValue() where the number value is bigger than the Java integer (32bit) limit might produce a wrong result instead of throwing an exception saying the number is too big. When not using a TokenBuffer parser, but when an implementation of ParserBase is used, I get some expected exceptions saying Numeric value ... out of range of int.

Here's a TokenBuffer example:

TokenBuffer tb = new TokenBuffer(new ObjectMapper(), false);
tb.writeNumber("-4294967295");

JsonParser jp = tb.asParser();
jp.nextToken();

System.out.println("jp.getIntValue() = " + jp.getIntValue());
// returned value is 1

(using a recent 2.9.1-SNAPSHOT build)

However as you can see here, ParserBase.getIntValue() tries to convert the int, which if not valid fails, and throws the expected exception of int overflow.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions