Skip to content

PathMatchingResourcePatternResolver should close jar file from JarURLConnection if not cached [SPR-6295] #10961

Closed
@spring-projects-issues

Description

@spring-projects-issues

Stoehr Sukachevin opened SPR-6295 and commented

The "org.springframework.core.io.support.PathMatchingResourcePatternResolver#doFindPathMatchingJarResources(Resource, String)" method does not close a Jar file that it opens if it gets it from a JarURLConnection directly. The reason that is given in the code as to why the Jar file is not closed from a JarURLConnection is because the JarURLConnection "might cache the file reference". However, "setUseCaches(false)" is called on the JarURLConnection instance when it is first obtained presumably because we do not want any caching done. (And internally, at least for the Sun JVM version of the JarURLConnection subclass [sun.net.www.protocol.jar.JarURLConnection], if "useCaches" is "false", then the Jar file is closed after it is no longer needed [e.g., when the input stream from the JarURLConnection instance is closed].)

The net result of this is that the Jar file will NOT be closed for an undetermined
length of time (until the Jar file's "finalize()" method is called by the GC), and in Windows, the Jar file will most likely have an open-file lock on it unnecessarily after this method completes.

The solution is to simply close the Jar file unconditionally at the end of the method. (Curently, it is only closed when the "newJarFile" flag is set, which is not the case when the Jar file is retrieved from a JarURLConnection directly.)


Affects: 2.5.6

Issue Links:

Referenced from: commits 4c96447

1 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions