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

'JsonParser.getCurrentLocation()` byte/char offset update incorrectly for big payloads #603

Closed
fabienrenaud opened this issue Feb 25, 2020 · 3 comments
Milestone

Comments

@fabienrenaud
Copy link
Contributor

The following test passes with jackson-core-2.10.0 and fails jackson-2.10.1:

    public void testBigPayload() throws IOException {
        JsonLocation loc;
        JsonParser p;

        String doc = "{\"key\":\"" + generateRandomAlpha(50000) + "\"}";

        p = createParserUsingStream(JSON_F, doc, "UTF-8");

        assertToken(JsonToken.START_OBJECT, p.nextToken());
        loc = p.getTokenLocation();
        assertEquals(0, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(1, loc.getColumnNr());
        loc = p.getCurrentLocation();
        assertEquals(1, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(2, loc.getColumnNr());

        assertToken(JsonToken.FIELD_NAME, p.nextToken());
        loc = p.getTokenLocation();
        assertEquals(1, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(2, loc.getColumnNr());
        loc = p.getCurrentLocation();
        assertEquals(8, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(9, loc.getColumnNr());

        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        loc = p.getTokenLocation();
        assertEquals(7, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(8, loc.getColumnNr());
        loc = p.getCurrentLocation();
        assertEquals(8, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(9, loc.getColumnNr());

        p.getTextCharacters();
        loc = p.getTokenLocation();
        assertEquals(7, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(8, loc.getColumnNr());
        loc = p.getCurrentLocation();
        assertEquals(doc.length() - 1, loc.getByteOffset());
        assertEquals(-1L, loc.getCharOffset());
        assertEquals(1, loc.getLineNr());
        assertEquals(doc.length(), loc.getColumnNr());
    }

    private String generateRandomAlpha(int length)
    {
        StringBuilder sb = new StringBuilder(length);
        Random rnd = new Random(length);
        for (int i = 0; i < length; ++i) {
            // let's limit it not to include surrogate pairs:
            char ch = (char) ('A' + rnd.nextInt(26));
            sb.append(ch);
        }
        return sb.toString();
    }

In 2.10.1, the test fails with the following output:

Expected :50009
Actual   :44019

Regression was introduced by PR #557 (issue #455)

fabienrenaud pushed a commit to fabienrenaud/jackson-core that referenced this issue Feb 25, 2020
@cowtowncoder
Copy link
Member

Oh wow. Thank you for reporting this, providing fix. And yes, fix for #455 probably was it just looking at release notes. Should have caught that...

@fabienrenaud
Copy link
Contributor Author

@cowtowncoder Would be great if this could get released asap in 2.10.3. Thank you.

cowtowncoder pushed a commit that referenced this issue Feb 26, 2020
Fixed issue #603 (location offset regression in 2.10.1)
@cowtowncoder cowtowncoder added this to the 2.10.3 milestone Feb 26, 2020
@cowtowncoder cowtowncoder changed the title [regression in 2.10.1] JsonParser.getCurrentLocation byte offset is very far off for big payloads 'JsonParser.getCurrentLocation()` byte/char offset update incorrectly for big payloads Feb 26, 2020
@cowtowncoder
Copy link
Member

@fabienrenaud Yes, I am thinking of when to release 2.10.3 -- full release takes hours and I don't have such time slots that often these days to use for a hobby. But maybe I can do that over this weekend; if not, then next one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants