Skip to content

Change in Jar usecache behavior with Spring 6.1.x causing java.lang.IllegalStateException: zip file closed #34678

Closed
@rahulsh1

Description

@rahulsh1

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 invocations

After 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.

// 5.3.x
public static void useCachesIfNecessary(URLConnection con) {
  con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
}

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.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions