Skip to content

Illegal access reflection #1091

@aelgn

Description

@aelgn

Javers 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.

#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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions