java.nio.Buffer在运行时未加载clear()方法 [英] java.nio.Buffer not loading clear() method on runtime

查看:413
本文介绍了java.nio.Buffer在运行时未加载clear()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我是使用Java代理进行注入的项目的开发人员。

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.

对于大多数用户来说,一切都很好,但是有些人在java.nio.IntBuffer上遇到问题没有加载clear()(从Buffer继承)

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)

错误:

java.lang.NoSuchMethodError: java.nio.IntBuffer.clear()Ljava/nio/IntBuffer;

然后是堆栈跟踪,它只是第一次在我们的代码中调用clear()。

Then the stacktrace, which simply gives the first time clear() is called in our code.

这是什么原因(除了Java在运行时未加载外),我该如何解决?

What is the cause of this (besides the fact that Java isn't loading at runtime) and how do I fix it?

推荐答案

感谢Janez Kuhar的评论,并进行一些挖掘是由于JDK9破坏了兼容性。在我们的代码中,我们调用IntBuffer.clear()并期望它返回Buffer,但是在JDK9中,它们使所有Buffer方法都返回子类型(即ByteBuffer或IntBuffer而不是Buffer),因此运行JRE8的人们(我们的大部分用户群)遇到NoSuchMethodError的问题,因为返回类型不兼容,必须像这样强制转换

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());

这篇关于java.nio.Buffer在运行时未加载clear()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆