spf4j icon indicating copy to clipboard operation
spf4j copied to clipboard

Illegal reflective access on Java 9+

Open marinier opened this issue 4 years ago • 2 comments

When I run my unit tests, I get this warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.spf4j.log.SLF4JBridgeHandler$3 (file:/C:/Users/bob.marinier/.m2/repository/org/spf4j/spf4j-slf4j-test/8.8.1/spf4j-slf4j-test-8.8.1.jar) to field java.util.logging.LogRecord.needToInferCaller
WARNING: Please consider reporting this to the maintainers of org.spf4j.log.SLF4JBridgeHandler$3
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

This is a Java 9+ issue. The answer to this question has more info: https://stackoverflow.com/questions/50251798/what-is-an-illegal-reflective-access

I can think of a few ways to potentially address this:

  • Avoid performing these reflective accesses. This may not be possible.
  • Release a Java 11 version (Java 9 and 10 are already EOL) of this project. Probably all you need to do is add a module-info.java file with the appropriate content.
  • Update the README to include instructions for working around this problem. In particular, the following JVM args need to be added:
--add-opens=java.logging/java.util.logging=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED

(The first line addresses the specific warning above. The second line addresses another warning that comes up when the first one is addressed. Note, the previous suggestion would have this information in the module-info.java file, and thus end users wouldn't have to do this themselves.)

marinier avatar Apr 30 '20 17:04 marinier

thank you for reporting this.

This is caused by a workaround for accessing caller class+method without inference which is costly when transforming java.util.LogRecord to a slf4j log record...

There are some JDK issues related to this: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4515935 I also filed a JDK request for enhancement: 9064834

For now I will add your suggestions to the documentation. Will keep this issue open until I start using JDK 11 for building spf4j and be able to leverage the module system, etc...

zolyfarkas avatar Apr 30 '20 19:04 zolyfarkas

TODO: review: org.spf4j.base.Throwables org.spf4j.base.Reflections

zolyfarkas avatar Jun 02 '20 21:06 zolyfarkas