加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java.lang.IllegalAccessError:尝试从类Entity访问字段Concrete

发布时间:2020-12-14 05:33:00 所属栏目:Java 来源:网络整理
导读:java.lang.IllegalAccessError: tried to access field ConcreteEntity.instance from class Entity 好的,所以这里是交易.我正在尝试访问ConcreteEntity.instance,这是一个默认的ClassLoader中存在的访问类型默认的字段,而Entity.getInstance是存在于一个小

java.lang.IllegalAccessError: tried to access field ConcreteEntity.instance from class Entity

好的,所以这里是交易.我正在尝试访问ConcreteEntity.instance,这是一个默认的ClassLoader中存在的访问类型默认的字段,而Entity.getInstance是存在于一个小孩ClassLoader中的一种方法.

请记住,它们都在同一个包中,但是会抛出一个IllegalAccessError.有没有解决这个问题,不涉及我实际将Entity类加载到与ConcreteEntity相同的ClassLoader中?

0 new #14 <Entity>
 3 dup
 4 aload_0
 5 invokevirtual #18 <Adapter.getInstance>
 8 checkcast #20 <sl>
11 getfield #24 <sl.d>
14 invokespecial #25 <Entity.<init>>
17 areturn

通过jclasslib检索的字节码是异常生成“编译后”.

谢谢Gamb清理帖子.

解决方法

参见 my answer到 a similar question,除了你的情况,很明显你正在处理多个类加载器:

jvm认为从不同类加载器加载的类可以在不同的“运行时包”中,即使它们具有相同的包名称.从the jvm spceification起,第5.3节:

At run time,a class or interface is determined not by its name alone,but by a pair: its fully qualified name and its defining class loader. Each such class or interface belongs to a single runtime package. The runtime package of a class or interface is determined by the package name and defining class loader of the class or interface.

在第5.4.4节中:

A field or method R is accessible to a class or interface D if and only if any of the following conditions is true:

R is either protected or package private (that is,neither public nor protected nor private),and is declared by a class in the same runtime package as D.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读