Illegal access reflection
See original GitHub issueJavers uses reflection setAccessible on types, see JaversMember:95. If you want to diff a class with non-public fields of a java.lang type (like String, Locale etc…) setAccessible is considered an illegal access operation.
This has just resulted in runtime warnings but with java 16 out the default is to deny these operations. It is still possible to override this behavior with the vm arg --illegal-access=warn, but this will be removed in a future JVM release.
A more granular way is to add the module import with vm args for each sub module in java.base --add-open.
But this will require all downstream projects to change their runtime config, which is much more cumbersome than to declare the modules in a module-info.java file in javers.
https://github.com/javers/javers/issues/911
Steps To Reproduce
- create diffable dto class with a private final Locale member
- launch with java 16
- diff it
-> exception:
java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.util.Map java.util.Locale.CONSTANT_LOCALES accessible: module java.base does not "opens java.util" to unnamed module @1c53fd30
static class Qwop {
private final Locale l;
Qwop(final Locale l) {
this.l = l;
}
}
...
final Javers javers = JaversBuilder.javers().build();
javers.compare(new Qwop(Locale.US), new Qwop(Locale.CHINA));
Javers’ Version 5.14.0 & 6.1.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:14 (9 by maintainers)

Top Related StackOverflow Question
The problem with
java.util.Localeis fixed in 6.2.3Localeshould be added toWellKnownValueTypes, please contribute a PR