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
ArrayIndexOutOfBoundsException when using Json.decodeFromStream #1709
Comments
(again, sorry for the quite long JSON reproduction, but my knowledge of JSON and serialization wasn't quite good enough to determine how to provide a simpler reproduction) |
I'm also experiencing this issue — same versions as @bishiboosh. I can't upload a full reproducer to GitHub at this time, but a basic outline is that the issue occurs when I attempt to parse this file: https://github.com/spdx/license-list-data/blob/master/json/details/GPL-1.0.json. Perhaps the length, or presence of escapes and unicode characters in a few of the fields is what's causing the issue? @bishiboosh encountered this with randomly-generated data, so "long, complex strings" could be a commonality. Lines 317 to 332 in b746ba8
|
I added some debugging statements to the portion of
|
Okay, here's the specific text from
The next part of the line, where it's failing, is (after
Still not clear why this is failing. It appears to just be the escape before the double-quote, which is present in many other places. I notice that the serializer is adding extra escapes ( |
Here's a strange issue that I encountered while debugging this. Given the following code, where val json = Json {
ignoreUnknownKeys = true
}
@Serializable
data class Detail(
val licenseId: String,
val name: String,
val licenseText: String,
val licenseTextHtml: String,
val standardLicenseHeader: String?,
val standardLicenseHeaderHtml: String,
val licenseComments: String?,
val crossRef: List<LicenseCrossRef>,
val seeAlso: List<String>
)
fun main() {
val detail: Detail = Path.of("/tmp/GPL-1.0.json").inputStream().use {
json.decodeFromStream(it)
}
} However, if I remove any fields from the
edit: I just noticed that both my and bishiboosh's issue happens at 16384. That's especially curious. I don't currently understand the significance of 16384 in this context, but given that 16kib = 16,384 bytes I'm guessing it could be a default size limit for the inputstream. e.g. https://www.baeldung.com/java-buffered-reader, https://stackoverflow.com/q/37680780 |
I think #1706 should fix this. You can check out the branch and test it, or I'll check with the test case you provided a bit later |
@sandwwraith I'm not in any rush so I'll let you add the test case and I'll test once the next release appears |
@sandwwraith I built that locally and it works without issue 🎉 :
|
Fixed in 1.3.0 |
When using
Json.decodeFromStream
, the following exception occurs:This a bug I've caught while using randomly-generated data in unit tests, so the data which needs to be used to reproduce is unfortunately a bit complex.
From what I've been able to gather (but my intuition may be false), this happens in the following code block in
AbstractJsonLexer.kt
:Seems like it happens when
char
isSTRING_ESC
(so we're waiting to see what have been escaped), but at the same time we're at the end of the chunk and nothing is loaded because we enter into the first branch of theif
.To Reproduce
I've made a sample project with the incriminated data at https://github.com/bishiboosh/kotlin-serialization-error, the error can be replicated by launching the
main
method inmain.kt
Expected behavior
When using
Json.decodeFromString
, no error occurs, sodecodeFromStream
should not have issue with this JSON.Environment
The text was updated successfully, but these errors were encountered: