On java 17 there are some higher restrictions for some internal modules.
I'm not sure if you have this issue on the implementation code or "just" for testing. From my experience this issue is more common for the tests because most mocking frameworks will break the restrictions...
However you have to give in these parameters
--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED
If you need this for unit testing you and using maven then you could use a configuration like this:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0</version> <configuration> <argLine> --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED </argLine> </configuration> </plugin> </plugins> </build>