Repository navigation
Docs. Troubleshooting test run configuration with Java 17 #2047
Description
Activity
- addedctg-documentationImprovements or additions to documentationImprovements or additions to documentationctg-enhancementNew feature, improvement or change requestNew feature, improvement or change request
on Mar 27, 2023 @alisevych Please check the Troubleshooting section in Wiki.
I would correct the following wording not to mess the user:
build an Object assemble modelto justbuild an ObjectAlso the keys in the first part can be joined into one String so that it can be easily copy-pasted.
@alisevych Please verify the fix.
Reacted by Alena LisevychWe've just identified that adding VM options to Run configuration doesn't work for Gradle run configuration in IDEA.
In case of Gradle project with JDK 17 and a test that uses reflection, the user needs to configure the task that runs this test.
Add VM options to the test task inbuild.gradlefile, like following:Text to insert:
jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED", "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED"]The list of modules to open can be different.
User needs to open the java modules, which their classes are in.For example, in OwnerControllerTest in spring-petclinic, there is setFiled called for
java.util.LinkedHashMap
The following exception message is in console:java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.LinkedHashMap$Entry java.util.LinkedHashMap.head accessible: module java.base does not "opens java.util" to unnamed module ...
So the following string should be added to VM options:
`"--add-opens", "java.base/java.util=ALL-UNNAMED"``
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone

Description
Add Troubleshooting section in User guide on how to run tests with Java 17 using reflection.
In order to support user with bug
Please consider the best place for Troubleshooting section.
Expected behavior
UnitTestBot sometimes cannot combine Object assemble model without using reflection.
Sometimes a private field needs to be set or got.
Reflection methods using setAccessible is forbidden in Java 17+.
User can add keys to the JVm in order to run the tests.
Otherwise UtUtils methods can fail.
Environment
IntelliJ IDEA Ultimate 2023.3.*
Potential alternatives
Possibility to add needed keys automatically can be very complex.
One can see the list of keys needed to run tests for UnitTestBot: build.gradle.kts
Context
UnitTestBot plugin will be working on Java 17 starting from Release 2023.3