问题
So I am a developer for a project that uses a java agent to inject. It should be noted though that this error occurs after main is called.
Everything is going fine for most users, but a few are having an issue where java.nio.IntBuffer isn't loading clear() (inherited from Buffer)
Error:
java.lang.NoSuchMethodError: java.nio.IntBuffer.clear()Ljava/nio/IntBuffer;
Then the stacktrace, which simply gives the first time clear() is called in our code.
What is the cause of this (besides the fact that Java isn't loading at runtime) and how do I fix it?
回答1:
Thanks to the comment from Janez Kuhar and doing some digging this is caused by JDK9 breaking compatibility. In our code we call IntBuffer.clear() and expect it to return Buffer, but in JDK9 they made all Buffer methods return the child type (i.e. ByteBuffer or IntBuffer as opposed to just Buffer), therefore people running JRE8 (most of our userbase) experience NoSuchMethodError's because the return type is incompatible and must be casted like this
someMethod(((Buffer)intBuffer).clear());
来源:https://stackoverflow.com/questions/48693695/java-nio-buffer-not-loading-clear-method-on-runtime