1

I am migrating a rather large monolith spring boot application from Java 8 to Java 11. After i've fixed the removed JEE modules, i ran into several reflection errors based on the strong encapsulation by the new introduced module system concept.

Starting the application works with Java 11, however, performing a clean install via Maven doesnt work. There are several test failures caused by an InaccessibleObjectException due to reflection vs strong encapsulation.

java.lang.reflect.InaccessibleObjectException: Unable to make field private jdk.internal.reflect.MethodAccessorImpl jdk.internal.reflect.DelegatingMethodAccessorImpl.delegate accessible: module java.base does not "opens jdk.internal.reflect" to unnamed module @6a969fb8 at com......(some Test-Method).

I've already tried the solution suggested in that post How to solve InaccessibleObjectException ("Unable to make {member} accessible: module {A} does not 'opens {package}' to {B}") on Java 9?.

But neither using the parameter --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED as Maven argument nor storing it in the maven jvm.config helps.

Are there any other approaches to get rid of these Exceptions?

Tommy
  • 27
  • 1
  • 1
  • 7

1 Answers1

4

You should add these flags not to maven itself, but to your test configurations, as tests are probably running in separate jvm: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

<argLine>

Arbitrary JVM options to set on the command line. User property is: argLine.

Or some other similar flag to other test plugin if you are using something else.

Note that you can also probably fix some of these issues by not using this internal API at all, so you should try this first.

GotoFinal
  • 3,585
  • 2
  • 18
  • 33