【发布时间】:2019-09-30 10:27:23
【问题描述】:
我有一个 Kotlin 项目,它使用 Guice 进行 DI,最近从 JDK 8 -> 11 更新。它现在在运行时发出以下错误:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/Users/matt/.gradle/caches/modules-2/files-2.1/com.google.inject/guice/4.2.2/6dacbe18e5eaa7f6c9c36db33b42e7985e94ce77/guice-4.2.2.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
应该如何解决这个警告?
【问题讨论】:
-
感谢@StefanZobel 的链接——我不得不承认,在查看了关于该问题的(相当长的)线程之后,我不清楚这是否是“等待指导修复它”,或者如果有一些修复可以同时应用。
-
我的理解是cglib 3.2.5增加了对使用Methodhandles.Lookup.defineClass的支持。这是支持的 API,用于将一个类注入到与另一个类相同的运行时包中。我对 Guice 问题的解读是它捆绑或重新打包了 cglib 的副本,我不知道是哪个版本,但它可能是依赖于破解非公共 ClassLoader.defineClass 方法的旧版本“非法反射访问”警告很重要,因为一旦 java.base 被完全封装,黑客就会中断。
-
确认此问题已于 2021 年 2 月在 Guice 5.0.1 中得到修复。