我想看看为什么我会收到"警告:发生了非法的反射访问操作"我想在此之前摆脱这些警告,首先我想检查它在我的代码中实际发生的位置。因为我读过
"对任何此类包的第一次反射访问操作会导致发出警告,但在此之后不会发出警告。此单个警告介绍如何启用进一步的警告。此警告无法抑制。
所以要得到进一步的警告
所以我提到了 --illegal-access=deny 以及 IntelliJ 中的 --add-exports 选项。
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="XXX" options="--illegal-access=deny --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED" />
</option>
然后我得到了错误:java:错误:无效标志:--非法访问=拒绝
这些是警告
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:xxx/xxx/xxx/xstream-1.4.10.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
反射访问发生在运行时,因此无法在编译时检测到它。如果要删除警告,可以将命令行选项--add-opens
添加到运行配置中:
--add-opens=java.base/sun.net.www.protocol.http=ALL-UNNAMED
--add-opens
使包在运行时sun.net.www.protocol.http
可访问,而不会发出警告。
但是,我建议不要使用此选项,而是找出为什么会发生这种非法反射访问并尝试消除它。