Change in Jar usecache behavior with Spring 6.1.x causing java.lang.IllegalStateException: zip file closed #34678
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: regression
A bug that is also a regression
Milestone
We use the
PathMatchingResourcePatternResolver
outside of Spring to discover resources on the classpath, as it provides significant performance benefits as compared to anything else we came up with.One such class looks for resources using a ForkJoinPool to scan for multiple patterns in the classpath using
PathMatchingResourcePatternResolver
. This worked fine with Spring 5.3.x.Post migration to Spring 6.1.x, we started seeing a random
java.lang.IllegalStateException: zip file closed
on some of the invocationsAfter looking at the implementation differences between the 5.3.x and 6.1.x, it appears a change was done to remove the call to
ResourceUtils.useCachesIfNecessary(jarCon);
The 5.3.x implementation sets the
useCache
on the JarConnection as false (since there is no JNLP) while there is no such thing happening with 6.1.x.This appears to be related to JDK-6947916 where inconsistent values of the useCache flag may result in this behavior for a multi-threaded invocation.
With Spring 5.3.x, this was explicitly set to be false while now with Spring 6.1.x, that guarantee does not exist resulting in the race condition and random "zip file closed" exceptions.
The text was updated successfully, but these errors were encountered: