I've started a project using java 16 and I'm getting errors in the project all over the place:
An error has occurred. See error log for more details.
Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @6dfcffb5
It looks like the code I have from different version of java is not working in this particular version. Any idea what I need to change maybe in the pojo class. I have only 1 pojo in the application cause it is micro service.
Thanks.
You are using old versions of Spring / Spring Boot that are incompatible with, and do not support Java 16.
According to the Spring Compatibility Matrix, you will need to use Spring 5.3.x or later for Java 16 compatibility.
For Spring-Boot, you need 2.7.1 or later for Java 17 compatibility ... according to this Spring And Spring Boot Versions page.
Also note that Java 16 is end-of-life as well. You probably should be using one of the LTS versions of Java; i.e. Java 8, 11, 17, 21 ...
(Winding back to an earlier Java LTS would "fix" the Spring compatibility issue, but IMO rolling Spring and Java forward is better. You don't want to be developing a new project on top of a base that is already outdated.)
The actual problem you are seeing is due to something (probably a Spring Boot custom classloader) accessing an "internal" API. This leads to warning messages since Java 9 and is blocked in Java 14 and later. This Q&A gives some background:
The simple and best solution is to use only "supported" versions of Java for your selected versions of Spring and Spring Boot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With