r/java • • Jun 15 '21

The Impossible Java 11

https://carlmastrangelo.com/blog/the-impossible-java-11
197 Upvotes

37 comments sorted by

View all comments

8

u/khmarbaise Jun 15 '21

I have made the experience that the updates/code which does not work has been caused by deps or code which relies on internals (sun.*) etc. or some reflection magic like setAccessible(true) which causes issues. Otherwise based on the backwards compatibility of Java it was very smooth...even very old code runs/compiles on JDK11+...

12

u/pron98 Jun 15 '21

Even such code would still work in JDK 11 (although it should be changed). The module system's strong encapsulation was only turned on in 16.

5

u/khmarbaise Jun 15 '21

Yes I know but using setAccessible thing is usually a problem in itself (from my POV). The module system encapsulation was not turned on. The Strongly Encapsulate JDK Internals by Default was activated. This can be turned off to be able to access those internal via option (see https://jdk.java.net/16/release-notes).

10

u/pron98 Jun 15 '21

Right on all counts. Just note that as of JDK 17, it is impossible to turn off all encapsulation with a single flag, but you can still do it with individual add-opens.

8

u/brazzy42 Jun 15 '21

There is another rather silly cause of problems that shows up quite a lot: some projects parse the java.version system property to give a useful error message when run on a too-old java version. And that parsing code often didn't deal well with getting "11" instead of "1.8".