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

Dev Tools reload and SpEL loaded classes within Thymeleaf templates #42690

Closed
mvitz opened this issue Oct 15, 2024 · 4 comments
Closed

Dev Tools reload and SpEL loaded classes within Thymeleaf templates #42690

mvitz opened this issue Oct 15, 2024 · 4 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@mvitz
Copy link
Contributor

mvitz commented Oct 15, 2024

In one of our Thymeleaf templates we have the following code:

...
<td th:if="${foobar instanceof T(some.pkg.FooBar)}">Matches</td>
...

This generally works and when foobar is an instance of FooBar the td is shown.

But when I start the application with Dev Tools enabled, and I change something after reloading, the td is no longer shown.
After I suspected that class loading may be the issue, I added the following code:

<td th:text="${foobar.getClass().getClassLoader()}"></td>
<td th:text="${T(some.pkg.FooBar).getClassLoader()}"></td>

After each change and reload, this shows that the ClassLoader of the foobar instance is a new RestartClassLoader but the ClassLoader of the T(some.pkg.FooBar) stays the initial one and therefore the instanceof returns false.
I don't know if it's possible, but it would be nice if the class within the Thymeleaf SpEL would be loaded by the same ClassLoader instance that loads the rest of the web application, as this would not alter the application "logic" in that case.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 15, 2024
@philwebb
Copy link
Member

@mvitz Do you by any chance have a sample application you can provide?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Oct 15, 2024
@mvitz
Copy link
Contributor Author

mvitz commented Oct 16, 2024

@philwebb, of course, I put a simple reproducer to https://github.com/mvitz/devtools-thymeleaf-classloader
The README contains a screenshot of the index page after the initial start and a second one after adding just a blank line to the Application.java file and letting the DevTools reload happen.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 16, 2024
@philwebb
Copy link
Member

Thanks for the sample. I'm pretty sure this is caused by org.thymeleaf.spring6.expression.ThymeleafEvaluationContext storing ThymeleafEvaluationContextACLTypeLocator in the TYPE_LOCATOR static. That survives restarts and has a classloader stored inside it.

I'm not really sure how we can fix it, the best thing I can think of so far is to try and reset that static field using reflection.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 19, 2024
@philwebb philwebb added this to the 3.2.x milestone Oct 19, 2024
@philwebb
Copy link
Member

I've tried a few reflection hacks, but I don't think we can fix this. I think we need to ask for a change to ThymeleafEvaluationContext. @mvitz Can you please open an issue with https://github.com/thymeleaf/thymeleaf-spring to see if they can update their code.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
@philwebb philwebb added for: external-project For an external project and not something we can fix and removed type: bug A general bug labels Oct 19, 2024
@philwebb philwebb removed this from the 3.2.x milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants