stefanbirkner / system-lambda

System Lambda is a collection of functions for testing code that uses java.lang.System
MIT License
211 stars 14 forks source link

illegal reflective access operation #10

Open cemeyer2 opened 4 years ago

cemeyer2 commented 4 years ago

Running a test suite that leverages WithEnvironmentVariables in a docker container based on openjdk:11-jdk, I get the following warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.github.stefanbirkner.systemlambda.SystemLambda$WithEnvironmentVariables (file:/root/.gradle/caches/modules-2/files-2.1/com.github.stefanbirkner/system-lambda/1.1.0/488b3059b67701b821355dafd952c0c7110f7ba9/system-lambda-1.1.0.jar) to field java.util.Collections$UnmodifiableMap.m
WARNING: Please consider reporting this to the maintainers of com.github.stefanbirkner.systemlambda.SystemLambda$WithEnvironmentVariables
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

The code executes fine, but the warning is slightly concerning if in fact a future release of the JVM will break this library. Is there something I can do in my code to not cause the illegal access?

Thanks!

stefanbirkner commented 4 years ago

Unfortunately not. You're right. The code may break in a future JVM because the environment variables support relies on internal details. AFAIK there es no other way apart from mocking the System class.

FreedomFaighter commented 1 year ago

31 has a log of where that issue begins in the tests

ashleyfrieze commented 1 year ago

https://www.baeldung.com/java-unit-testing-environment-variables#3-when-reflective-access-doesnt-work