[java] Don't cache jar files when loading classes

This makes sure, that the underlying JarFiles are closed
as soon as the streams to read single classes are closed.
This commit is contained in:
Andreas Dangel
2023-10-18 16:07:17 +02:00
parent 95b1150e25
commit fbf2f77871

View File

@@ -8,6 +8,7 @@ package net.sourceforge.pmd.lang.java.symbols.internal.asm;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -48,7 +49,11 @@ abstract class Loader {
@Override
@Nullable
InputStream getInputStream() throws IOException {
return url.openStream();
URLConnection connection = url.openConnection();
// disable the cache, so that the underlying JarFile (if any) is closed, when
// the returned stream is closed - leaving no open files behind.
connection.setUseCaches(false);
return connection.getInputStream();
}
@Override