[
https://issues.apache.org/jira/browse/CONFIGURATION-794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17211884#comment-17211884
]
Rob Spoor commented on CONFIGURATION-794:
-----------------------------------------
I've done some investigation, and the problem lies here, in
{{FileHandler.load}}:
{code} InputStream in = null;
try
{
in = FileLocatorUtils.obtainFileSystem(locator).getInputStream(url);
loadFromStream(in, locator.getEncoding(), url);
}
...
finally
{
closeSilent(in);
}
}{code}
{{closeSilent}} calls the following {{close}} method:
{code} class JarURLInputStream extends java.io.FilterInputStream {
JarURLInputStream (InputStream src) {
super (src);
}
public void close () throws IOException {
try {
super.close();
} finally {
if (!getUseCaches()) {
jarFile.close();
}
}
}
}{code}
Here, {{getUseCaches()}} returns {{true}}, so the JAR file is not closed.
A quick fix, in {{DefaultFileSystem.getInputStream}}:
{code}// return url.openStream();
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();{code}
However, this definitely requires more consideration, as it disables caching
and therefore will open the JAR file every time.
> Unclosed file handle when reading config from JAR file URL
> ----------------------------------------------------------
>
> Key: CONFIGURATION-794
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-794
> Project: Commons Configuration
> Issue Type: Bug
> Affects Versions: 2.7
> Reporter: Robin Jansohn
> Priority: Major
>
> We read a properties file which is included in a JAR file. Unfortunately we
> cannot find any method to close the opened file handle after reading the
> properties.
> This currently means that the JAR file can only be deleted after the JVM
> shuts down. I'll open a PR which shows the behavior.
> We currently run our code mostly on Windows systems and Oracle JDK8.
> PR: https://github.com/apache/commons-configuration/pull/76
--
This message was sent by Atlassian Jira
(v8.3.4#803005)