Skip to content

Edoardo Vignati

– Always looking for something awesome –

Menu
  • About me
  • Studies
  • Publications
  • Skills
  • Portfolio
  • Projects
  • Career
  • Blog
  • Travels  
Menu

[SOLVED] WARNING: An illegal reflective access operation has occurred

Posted on 20/12/202024/02/2021 by Edoardo

This is intended to be a practical solution to disable specifically these types of logs in Java programs.

Please note that this solution requires a little bit of work.

As you can imagine, this warning is related to reflective operations called by our program or its dependencies.

Let’s assume that we are facing a warning like the following one:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on org.neo4j.memory.RuntimeInternals (jar:file:/home/user/workspace/explore/target/explore-1.0-with-dependencies.jar!/BOOT-INF/lib/neo4j-unsafe-4.1.2.jar!/) to class java.lang.String
WARNING: Please consider reporting this to the maintainers of org.neo4j.memory.RuntimeInternals
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

Take a look now to the class name at the end of the second line (highlighted in the red rectangle). In my case it’s java.lang.String

The next step is to find out the corresponding source module and package.

In this case the source module is java.base and the package is java.lang as you can see below:

We can now launch our program adding a specific JVM option:

--add-opens <source-module>/<package>=<target-module>(,<target-module>)*

In my case I’m going to add the following option:

java --add-opens=java.base/java.lang=ALL-UNNAMED -jar myapp.jar

After this you could have 2 different outputs:

  • the logs are completely disappeared
  • you are encountering another similar set of warnings

In the second case don’t worry and simply repeat the process above till you don’t see any other warning.

You can find more accurate information about reflection and JVM options at https://openjdk.java.net/jeps/261

Cheers


Buy Me A Coffee


This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Edoardo on Sortable list with jQuery (also on mobile)05/04/2022
  2. Katrin on Sortable list with jQuery (also on mobile)05/04/2022
  3. Edoardo on Sortable list with jQuery (also on mobile)07/02/2022
  4. Katrin Konrad on Sortable list with jQuery (also on mobile)07/02/2022

© 2022 Edoardo Vignati | Powered by Minimalist Blog WordPress Theme