0

I'm trying to see why I'm getting "WARNING: An illegal reflective access operation has occurred" I want to get rid of the those warnings before that first I want to check how may places it is actually happening in my code.Because I have read that

"The first reflective-access operation to any such package causes a warning to be issued, but no warnings are issued after that point. This single warning describes how to enable further warnings. This warning cannot be suppressed."

So to get the further warnings

So I mentioned --illegal-access=deny along with --add-exports options in IntelliJ.

<option name="ADDITIONAL_OPTIONS_OVERRIDE">
  <module name="XXX" options="--illegal-access=deny --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED" />
</option>

Then I got Error:java: error: invalid flag: --illegal-access=deny

These are the warnings

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
N V
  • 81
  • 1
  • 6
  • 5
    AFAIK those are VM flags only, not javac. (As reflection happens at runtime, not compile time) – Jorn Vernee Jan 21 '19 at 16:00
  • 2
    Jorn Vernee is correct, the `--illegal-access` option is a runtime option and doesn't make any sense at compile-time. – Alan Bateman Jan 22 '19 at 07:54
  • Thanks Jorn, But I mentioned the warning which I got in the above question. it asked me to use illegal access option to enable the further suppressed warnings. where should we mention that? – N V Jan 22 '19 at 13:54

1 Answers1

3

Reflective access happens at run time, so there is no way to detect it at compile time. If you want to get rid of the warning, you can add the command line option --add-opens to your Run Configuration:

--add-opens=java.base/sun.net.www.protocol.http=ALL-UNNAMED

--add-opens makes the package sun.net.www.protocol.http accessible at run time with no warnings.

However, I recommend not to use this option but instead figure out why this illegal reflective access is happening and try to eliminate it.

ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155