From a414fe21b3dbb6eed8154753949e130e147b91e7 Mon Sep 17 00:00:00 2001 From: WolfgangHG Date: Sat, 26 Oct 2024 12:10:21 +0200 Subject: [PATCH] [WELD-2800] Don't use jar cache in ServiceLoader.loadServiceFile --- impl/src/main/java/org/jboss/weld/util/ServiceLoader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/impl/src/main/java/org/jboss/weld/util/ServiceLoader.java b/impl/src/main/java/org/jboss/weld/util/ServiceLoader.java index c5789358b7..ceee8e47f3 100644 --- a/impl/src/main/java/org/jboss/weld/util/ServiceLoader.java +++ b/impl/src/main/java/org/jboss/weld/util/ServiceLoader.java @@ -22,6 +22,7 @@ import java.io.InputStreamReader; import java.lang.reflect.Constructor; import java.net.URL; +import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; @@ -173,7 +174,10 @@ private List loadServiceFiles() { private void loadServiceFile(URL serviceFile) { InputStream is = null; try { - is = serviceFile.openStream(); + URLConnection jarConnection = serviceFile.openConnection(); + //Don't cache the file (avoids file leaks on GlassFish). + jarConnection.setUseCaches(false); + is = jarConnection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String serviceClassName = null; int i = 0;