Java considers environment variables to be immutable, so this extension uses reflection to change them.
-This requires that the SecurityManager allows modifications and can potentially break on different operating systems and Java versions.
+
Java considers environment variables to be immutable, which is why this extension uses reflection to change them.
+This requires the SecurityManager to allow modifications and may break on different operating systems and/or Java versions.
Be aware that this is a fragile solution and consider finding a better one for your specific situation.
-For more details, see Warnings for Reflective Access.
[ERROR] WARNING: An illegal reflective access operation has occurred
-[ERROR] WARNING: Illegal reflective access by org.junitpioneer.jupiter.EnvironmentVariableUtils [...] to field [...]
-[ERROR] WARNING: Please consider reporting this to the maintainers of org.junitpioneer.jupiter.EnvironmentVariableUtils
-[ERROR] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
-[ERROR] WARNING: All illegal access operations will be denied in a future release
+
WARNING: An illegal reflective access operation has occurred
+WARNING: Illegal reflective access by org.junitpioneer.jupiter.EnvironmentVariableUtils [...] to field [...]
+WARNING: Please consider reporting this to the maintainers of org.junitpioneer.jupiter.EnvironmentVariableUtils
+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
@@ -549,12 +549,19 @@
Warnings for Reflective Access
+
This is because Java 17 is strongly encapsulated and the reflective access to JDK internals is no longer permitted.
+(For further details, see also JEP 403.)
+
+
The best way to prevent these warnings/errors, is to change the code under test, so this extension is no longer needed.
-The next best thing is to allow access to that specific package:
+However, some tests require environment variables to be cleared, set, or restored.
+In this case, we recommend using --add-opens to grant JUnit Pioneer access to the aforementiond internals:
-
--add-opens java.base/java.util=$TARGET_MODULE
+
# to access java.util.Collections$UnmodifiableMap.m
+--add-opens java.base/java.util=$TARGET_MODULE
+# to access java.lang.ProcessEnvironment.theEnvironment
--add-opens java.base/java.lang=$TARGET_MODULE
Depending on your IDE, these settings may not be picked up.
+Therefore, you possibly also have to include --add-opens in your test’s run configuration.