Avoid JarURLConnection
resource leak in AbstractFileResolvingResource.exists()
#34528
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
The
AbstractFileResolvingResource
in Spring 5.3.39 has a resource leak (seems to still be present at least in 6.2.2).The leak occurs when the
exists()
method is called on aUrlResource
obtained from a JAR/ZIP file which is not on the classpath.exists()
will open a connection and may then call a variation ofgetContentLengthLong()
on it to obtain the size of the resource to check if it exists by comparing the size to 0.Leak: Calling
getContentLengthLong()
on aJarURLConnection
opens the underlying JAR file. However, that file is then not closed anymore.The problem can be checked e.g. by using https://github.com/jenkinsci/lib-file-leak-detector
Here a stack using Spring 5.3.39
The issue e.g. prevents temporary folders from unit tests containing ZIP resources accessed through Spring to be deleted on Windows.
The text was updated successfully, but these errors were encountered: