Java Platform Module System

setAccessible is broken?

If you’ve ever written code using Core Reflection API, you wrote something like this:

Field field=...


Method method=...

This code works fine till JDK 8 . In JDK 9 incompatible change was made. Quote from JavaDoc of setAccessible() method. This quote is done from recent JDK 14, but it is (almost) the same was in JDK 9:

Even more, new method was added to Field/Method:

In the last minute of JDK 9 release the “big kill switch” was added as temporary solution for 1 release:

Indeed, –permit-illegal-access was changed to –illegal-access.

As for now, the last released JDK is 14. And the “big kill switch” is still in place.

Quote from documentation of --illegal-access for JDK-14:

Personally, I think weeking Core Reflection API was big design mistake. On Java conferences many people, including myself, still says, that they are using JDK 8. And when people that uses JDK 9 and later are asked whether they used modules, the majority of them still uses classpath.With this “big kill switch” in place user code that Java developer is writting can access JDK internals. So, effectively, modules “strong encapsulation” have failed big time.

P.S. Many popular libraries in maven central not works on JDK 9 and later with modules.



Senior Software Engineer at Pursway

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store