-
Notifications
You must be signed in to change notification settings - Fork 628
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
java.lang.NoSuchMethodError when parsing a JSON stream on Java 8 #2218
Comments
Actually, There seems to be no such option as So, I guess, casting manually is the easiest fix for this particular bug. There are only two |
but there is an option like |
@lukellmann, indeed. But here we need specifically the
Also, the default value for the Anyway, I'm just afraid of introducing such a change to the build process (and I obviously don't have enough knowledge to do that). I guess it may require some access to the TeamCity configs or what. So let the team think of it. |
Fixes #2326 An explicit cast is needed here due to an API change in Java 9, see #2218. In Java 8 and earlier, the `position(I)` method was final in `Buffer`, and returned a `Buffer`. In Java 9 and later, the method was opened, and `ByteFuffer` overrides it, returning a `ByteBuffer`. This causes a `NoSuchMethodError` when running a class, compiled with a newer Java version, on Java 8.
Fixes #2326 An explicit cast is needed here due to an API change in Java 9, see #2218. In Java 8 and earlier, the `position(I)` method was final in `Buffer`, and returned a `Buffer`. In Java 9 and later, the method was opened, and `ByteBuffer` overrides it, returning a `ByteBuffer`. This causes a `NoSuchMethodError` when running a class, compiled with a newer Java version, on Java 8.
Fixes #2326 An explicit cast is needed here due to an API change in Java 9, see #2218. In Java 8 and earlier, the `position(I)` method was final in `Buffer`, and returned a `Buffer`. In Java 9 and later, the method was opened, and `ByteBuffer` overrides it, returning a `ByteBuffer`. This causes a `NoSuchMethodError` when running a class, compiled with a newer Java version, on Java 8.
…2328) Fixes Kotlin#2326 An explicit cast is needed here due to an API change in Java 9, see Kotlin#2218. In Java 8 and earlier, the `position(I)` method was final in `Buffer`, and returned a `Buffer`. In Java 9 and later, the method was opened, and `ByteBuffer` overrides it, returning a `ByteBuffer`. This causes a `NoSuchMethodError` when running a class, compiled with a newer Java version, on Java 8.
There are 7 methods in ByteBuffer that have the problem described in #2218 and was attempted to be fixed in #2219. Unfortunately, the fix in #2219 was incomplete as another of these 7 methods is used in the same class. Also it could happen anytime and with similar cases, that this happens again and is only recognized very late.
Describe the bug
I suspect the JSON format to be prone to this issue: plasma-umass/doppio#497 (comment)
The problem seems to be in the
CharsetReader
's constructor, on the line #23:kotlinx.serialization/formats/json/jvmMain/src/kotlinx/serialization/json/internal/CharsetReader.kt
Lines 18 to 24 in 6dbb8a9
It seem that this class is compiled with a higher language level and, running on Java 8, causing the issue.
I've
javap
-ed theCharsetReader
class (from the 1.5.0 versio of the library) and although I see the its class version is 52 (Java 8) it seems to be not enough for this nasty bug. The bytecode seems to use theByteBuffer
, which is incorrect 👇It seems that a proper compiler option needs to be passed during the compilation process. The other way to solve this is using a manual cast.
To Reproduce
Please, refer to this minimal reproducible example: https://github.com/madhead/kotlinx-serialization-json-java8. Follow its README.
Basically, to reproduce the issues one needs to call
Json.decodeFromStream
on Java 8. As a result, he gets an exception like this:Expected behavior
No exception is thrown, the stream is parsed correctly.
Environment
The text was updated successfully, but these errors were encountered: