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

JsonGenerationException: Split surrogate on writeRaw() input thrown for input of a certain size #307

Closed
mtnaseef opened this issue Aug 1, 2016 · 2 comments

Comments

@mtnaseef
Copy link

mtnaseef commented Aug 1, 2016

In short, I am seeing the following exception while processing text that includes valid multi-byte Unicode characters, and adding or removing characters before the "problematic" characters can affect whether the exception is thrown.

$ java -classpath .:../../jackson-core/target/jackson-core-2.8.2-SNAPSHOT.jar BadMsg com.fasterxml.jackson.core.JsonGenerationException: Split surrogate on writeRaw() input (last character) at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1887) at com.fasterxml.jackson.core.json.UTF8JsonGenerator._outputRawMultiByteChar(UTF8JsonGenerator.java:1916) at com.fasterxml.jackson.core.json.UTF8JsonGenerator._writeSegmentedRaw(UTF8JsonGenerator.java:697) at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:611) at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:560) at com.fasterxml.jackson.core.base.GeneratorBase.writeRawValue(GeneratorBase.java:306) at BadMsg.main(BadMsg.java:17)

The simplest way to demonstrate this is code, so I will attach a sample program with a document that causes the error. Sorry for the ugly redacted text, but you can imagine some real words and other interesting strings in place of all the x's. Note that if I delete or add enough of the 'x' characters (doesn't matter where in the JSON they appear, as long as it's before the character that causes the exception) the exception will not be thrown. I believe the problem is in buffering the data that is passed to the lower level functions, but I have not debugged to that level.

@mtnaseef
Copy link
Author

mtnaseef commented Aug 1, 2016

I don't see a way to attach a file, so here's BadMsg.java in pastebin: http://pastebin.com/4PjDiMP1

@cowtowncoder
Copy link
Member

Thank you for reporting this, I am investigating it now.

It's bit of a nasty problem, caused by segmented nature of processing; if surrogate pair is located at boundary of segment buffer exception is thrown. So need to figure out a way to handle this case.

hubot pushed a commit to apache/incubator-livy that referenced this issue Nov 23, 2017
## What changes were proposed in this pull request?

https://issues.apache.org/jira/browse/LIVY-416

`com.fasterxml.jackson.core.JsonGenerationException` is sometimes thrown. The full stack trace is show on [JsonGenerationException.txt](https://github.com/apache/incubator-livy/files/1482566/JsonGenerationException.txt).

This is because of the Jackson's bug (FasterXML/jackson-core#307) which was fixed at Jackson 2.7.7.

To fix this issue, the version of Jackson should be updated from 2.4.4 to the latest one (2.9.2).

In addition, `com.google.guava:guava:15.0` was added to the dependencies because it was removed from the dependencies of `com.fasterxml.jackson.module:jackson-module-scala_{2.10,2.11}:2.9.2`.

* [com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.4](https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-scala_2.10/2.4.4)
* [com.fasterxml.jackson.module:jackson-module-scala_2.11:2.4.4](https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-scala_2.11/2.4.4)
* [com.fasterxml.jackson.module:jackson-module-scala_2.10:2.9.2](https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-scala_2.10/2.9.2)
* [com.fasterxml.jackson.module:jackson-module-scala_2.11:2.9.2](https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-scala_2.11/2.9.2)

## How was this patch tested?
By executing `mvn clean package`.

Author: Keiji Yoshida <kjmrknsn@gmail.com>

Closes #64 from kjmrknsn/LIVY-416.
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