Thymeleaf - InaccessibleObjectException: module java.base does not "opens java.util" to unnamed module

Enonic version: 7.13.1
OS: Enonic Cloud
lib-thymeleaf version: 2.0.1

We are being warned by Enonic Cloud team to upgrade our application to the latest XP version ASAP.
The application is hosted on Enonic Cloud.

Currently we are running on version 7.11.3 but we are experiencing errors when trying to upgrade to 7.13.1

We have many, many, many Thymeleaf expressions using EntrySet interations from a Maps. Previously it was just causing warnings but in the newest Java version they turned into errors.

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make public final java.lang.Object java.util.HashMap$Node.getKey() accessible: module java.base does not “opens java.util” to unnamed module ~3ec5552c

One example of Thymeleaf expression is the following:

<div data-th-each="hotelCategory:${tour.hotels}" data-th-remove="tag">
    <div data-th-if="${not #lists.isEmpty(tour.hotels[hotelCategory.key])}" data-th-remove="tag">
        <h2 data-th-if="${tour.hotels[hotelCategory.key][0].category}" data-th-text="${tour.hotels[hotelCategory.key][0].category}"></h2>
        <div data-th-remove="tag" data-th-if="${tour.hotels[hotelCategory.key][0].categoryDescription}" data-th-utext="${tour.hotels[hotelCategory.key][0].categoryDescription}"></div>
    </div>
</div>

Every KEY or VALUE access from th:each iterations on Maps cause those reflection/module access error.

Do you have any suggestion other than rewriting our controllers to not use map iteration?

.
PS.: I found one solution online asking me to use the following JVM arguments:

–add-opens java.base/java.lang=ALL-UNNAMED
–add-opens java.base/java.util=ALL-UNNAMED

Is that feasible on Enonic Cloud?

Is it a typo? 2.0.1 is almost three years old, current version is 2.1.0.

Thank you @ase
I was trying to identify the trade-off when choosing between upgrading thymeleaf or finding a simpler fix on enonic.
I end up with the upgrade and a bit of refactoring on th:insert/th:replace/th:include.

Solved.

1 Like

A rule of thumb: if there’s a version that is 3 years newer than the one you’re on - upgrade :slight_smile:

Thank you.
Additionally I would like to suggest adding that compatibility notice on release notes (since Java 17, from XP 7.13, is not compatible with Thymeleaf below 3.1 version), because older versions use unsafe operations (not allowed on Java 17)

And, if possible, add update the compatibility table from lib.thymeleaf github page: