Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lists created from Stream.toList() cannot be rendered correctly #948

Open
grzegorzbor opened this issue Mar 10, 2023 · 4 comments
Open

Lists created from Stream.toList() cannot be rendered correctly #948

grzegorzbor opened this issue Mar 10, 2023 · 4 comments

Comments

@grzegorzbor
Copy link

Thymeleaf 3.0.15, no Spring

Create a list from Stream, using the new Stream.toList() method (new method added in java 17 i think), and add this list to the Thymeleaf model.

Then in Thymeleaf template, call size() or isEmpty() on this list , e.g. th:if="${list.isEmpty}"
and thymeleaf throws the exception:
Unable to make public boolean java.util.ImmutableCollections$ListN.isEmpty() accessible: module java.base does not "opens java.util" to unnamed module

The workaround is to use the "old style" Stream.collect(Collectors.toList()) - this works fine.

@danielfernandez
Copy link
Member

I have not been able to reproduce this, your scenario works for me in 3.0.15. Please provide a sample project (ideally Spring Boot -based) demonstrating the issue.

@grzegorzbor
Copy link
Author

Hi Daniel

The whole point is not to use Spring. Spring injects the custom dialect, and with that custom dialect, i think it works fine. The problem is when you use the standard Thymleaf dialect. I'm attaching the simple test app. There 4 lines marked with "works" or "does not work", just uncomment each of them to compare results.
thymeal_collection_problem.zip

@jmiguelsamper
Copy link
Member

Hi @grzegorzbor

I checked your sample project and I think this is just a typo, instead of

th:if="${list.isEmpty}"

it should be

th:if="${list.isEmpty()}"

Otherwise, you are not calling the isEmpty() method but asking Thymeleaf to print the value of the property "isEmpty".

The same happened to me this morning and I arrived to your issue report :-)

@grzegorzbor
Copy link
Author

Hmm i doubt it is the case.

Firstly, the error reported by thymeleaf was
Unable to make public boolean java.util.ImmutableCollections$ListN.isEmpty() accessible: module java.base does not "opens java.util" to unnamed module

so it quite clearly tries to call the isEmpty() method.

Secondly, it doesn't explain why it fails on the Stream.toList(), but works fine with Stream.collect(Collectors.toList())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants