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

writeRawValue() corrupts state in FilteringGeneratorDelegate #588

Closed
vy opened this issue Dec 29, 2019 · 6 comments
Closed

writeRawValue() corrupts state in FilteringGeneratorDelegate #588

vy opened this issue Dec 29, 2019 · 6 comments

Comments

@vy
Copy link
Contributor

vy commented Dec 29, 2019

Below snippet causes a JsonGenerationException with Can not write a field name, expecting a value message. When FilteringGeneratorDelegate is removed, code works as expected against JsonGenerator. (Using jackson-core version 2.9.10.)

private static class NullExcludingTokenFilter extends TokenFilter {

    private static final NullExcludingTokenFilter INSTANCE = new NullExcludingTokenFilter();

    @Override
    public boolean includeNull() {
        return false;
    }

}

@Test
public void repro() throws IOException {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1_024);
         JsonGenerator jsonGeneratorDelegate = new ObjectMapper().getFactory().createGenerator(outputStream);
         FilteringGeneratorDelegate jsonGenerator = new FilteringGeneratorDelegate(
                 jsonGeneratorDelegate,
                 NullExcludingTokenFilter.INSTANCE,
                 true,
                 true)) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeNumberField("f1", 1);
        jsonGenerator.writeFieldName("f2");
        jsonGenerator.writeRawValue(new char[]{'1', '2', '.', '3', '-'}, 0, 4);
        jsonGenerator.writeNumberField("f3", 3); // BOOM!
        jsonGenerator.writeEndObject();
        jsonGenerator.flush();
        String json = outputStream.toString(StandardCharsets.UTF_8.name());
        System.out.println(json);
    }
}
@cowtowncoder
Copy link
Member

Ah. You are probably hitting either #580 or #582, both fixed for 2.10.2, not yet released.

If it is easy enough for you to check 2.10.2-SNAPSHOT (either built locally, or from Sonatype OSS repo), it'd be good to verify just to be sure.

@vy
Copy link
Contributor Author

vy commented Dec 31, 2019

Sorry, it still fails on the same line with the same message.

@cowtowncoder
Copy link
Member

I can not reproduce: this passes for me as expected (wrt fixes mentioned above), with build from 2.10 branch. Maybe snapshot builds have not been updated? I'll do explicit maven deploy just in case, but I do think one of (or both) those issues was what you saw.
Note that issue would occur with 2.10.1 as the fix was after that was released.

vy added a commit to vy/jackson-core that referenced this issue Jan 2, 2020
@vy
Copy link
Contributor Author

vy commented Jan 2, 2020

Sorry for the noise, you are right. I've cloned the repo to local, ran the above snippet against master, and it worked. Probably I used an older SNAPSHOT version in my previous check. I've created PR #589, of which I actually should have done in the first place, adding the above check to the tests. Closing this issue. Thanks for your prompt help.

@vy vy closed this as completed Jan 2, 2020
@cowtowncoder
Copy link
Member

No problem -- better safe than sorry! 2.10.2 now released.

@vy
Copy link
Contributor Author

vy commented Jan 8, 2020

Thanks so much @cowtowncoder! 🙏 I have never witnessed such a prompt and responsible support for such a popular F/OSS project. Keep up the great job!

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