Skip to content

Prevent stale class loaders being cached at SpEL type resolution mechanism #1071

@mvitz

Description

@mvitz

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.

A simple reproducer can be found at 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.

This was originally reported to Spring Boot at spring-projects/spring-boot#42690 and Phil Webb pointed me here.

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions