-
Notifications
You must be signed in to change notification settings - Fork 41.3k
Description
With the update from v3.4.4 to v3.4.5 we encountered two ClassNotFoundException
in combination with Spring Webflux and HATEOAS.
I compared what has changed between these two versions and only the following had changed:
- Spring Boot (of course)
- Spring Framework 6.2.5 to 6.2.6
- Reactor BOM 2024.0.4 to 2024.0.5
After using the previous versions of Spring Framework and Reactor, the error still persists and the only change is Spring Boot. The problem also exists with the current version 3.5.0.
There are two problems, the first relates to CollectionJsonAffordanceModelFactory
and the second to HtmlInputTypeFactory
.
stacktace-HtmlInputTypeFactory.txt
stacktace-CollectionJsonAffordanceModelFactory.txt
I have created a sample application to reproduce the error.
mvn package
java -jar .\target\cl-issue-demo-0.0.1-SNAPSHOT.jar
- in another console:
curl -v http://localhost:8080/hello
No response is received and the stacktrace is logged.
Java version is 21.
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode, sharing)
We were also able to create workarounds for both problems by triggering the static code on the main thread with an ApplicationListener
(please see ApplicationConfiguration
in the sample app).
@Bean
public ApplicationListener<ApplicationStartedEvent> hateoasWorkaround() {
// workaround classloader issues
return event -> {
// issue #1: org.springframework.hateoas.mediatype.collectionjson.CollectionJsonAffordanceModelFactory
var link = org.springframework.hateoas.Link.of("test");
org.springframework.hateoas.mediatype.Affordances.of(link).afford(HttpMethod.GET).build();
// issue #2: org.springframework.hateoas.mediatype.html.HtmlInputTypeFactory
var type = ResolvableType.forClassWithGenerics(Mono.class, ResolvableType.forClassWithGenerics(ResponseEntity.class, TestResponse.class));
org.springframework.hateoas.mediatype.PropertyUtils.getExposedProperties(type);
};
}
Activity
Somesh-coding commentedon Jun 17, 2025
[-][Regression] ClassNotFoundException starting with 3.4.5 in combination with Webflux and HATEOAS[/-][+]ClassNotFoundException starting with 3.4.5 in combination with Webflux and HATEOAS[/+]snicoll commentedon Jun 17, 2025
Thanks for the report and the sample. This seems to be a regression introduced by 4af0ee20d1e0c86cd2f9.
SpringFactories#getSpringFactoriesInstances
is now creating theSpringResourceLoader
forMETA-INF/spring.factories
. It's cached which means that further attempt to load any factory from that file won't have the propert classloader as before.wilkinsona commentedon Jun 17, 2025
I think there are conflicting requirements here:
Both of these requirements are reasonable. Unfortunately, as far as I can tell, they cannot be supported at the same time while Framework's cache pollution problem remains.
Prior to 4af0ee2, the cache pollution meant that only the second requirement was met. After it, only the first requirement is met.
Given that the first requirement is new in 3.5, I'm leaning towards reverting 4af0ee2 in at least 3.3.x to restore the previous behavior in our final OSS 3.3.x release. For 3.4.x and 3.5.x we can then hopefully get a fix into Framework so that both requirements can be met.
philwebb commentedon Jun 17, 2025
+1 to reverting
philwebb commentedon Jun 18, 2025
We discussed this today and we've decided reverting is the least bad option. We'll ultimately need a fix in Framework.
[-]ClassNotFoundException starting with 3.4.5 in combination with Webflux and HATEOAS[/-][+]Loading from spring.factories may fail with a ClassNotFoundException when the TCCL changes between calls[/+]Revert "Work around Spring Framework cache pollution bug"