InputStream may leak in JarClassPath openClassfile (original) (raw)
I use javassist to modify method in jar. The jar file which to be modified will be opened after process.
It will return JarURLInputStream When jar file is opened by openClassfile of JarClassPath.
It will check cache when JarURLInputStream close.
class JarURLInputStream extends java.io.FilterInputStream {
JarURLInputStream (InputStream src) {
super (src);
}
public void close () throws IOException {
try {
super.close();
} finally {
if (!getUseCaches()) {
jarFile.close();
}
}
}
}
I modified openClassfile in JarClassPath like this. It will be ok.
public InputStream openClassfile(String classname) throws NotFoundException
{
URL jarURL = find(classname);
if (null != jarURL)
try {
URLConnection urlConnection = jarURL.openConnection();
urlConnection.setUseCaches(false);
return urlConnection.getInputStream();
}
catch (IOException e) {
throw new NotFoundException("broken jar file?: "
+ classname);
}
return null;
}