question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Illegal access reflection

See original GitHub issue

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.

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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bartoszwalacikcommented, Jul 4, 2021

The problem with java.util.Locale is fixed in 6.2.3

1reaction
bartoszwalacikcommented, Jul 2, 2021

Locale should be added to WellKnownValueTypes, please contribute a PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is an illegal reflective access? - java - Stack Overflow
Run it with --illegal-access=deny to get to know about and avoid opening packages from one module to another without a module declaration ...
Read more >
Java 9 Illegal Reflective Access Warning - Baeldung
Before Java 9, the Java Reflection API has a superpower: It could gain access to the non-public class members without limitation.
Read more >
An illegal reflective access operation has occurred when ...
You will see An illegal reflective access operation has occurred warning when installing and using AM (including Amster and ssoadm tools), Java ...
Read more >
How to fix “an illegal reflective access operation has occurred”
The "an illegal reflective access operation has occurred" warning message is related to the unauthorized access to parts of the JDK made by ......
Read more >
Illegal access in Java 16 A.K.A. 'My program crashes!'
This means that if your application summons the demons of deep reflection, either in the code you & your team wrote, or in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found