From 7700b0414aa20e70826d850bb3d71179f968f2cc Mon Sep 17 00:00:00 2001 From: emeroad Date: Tue, 7 Jan 2025 11:07:09 +0900 Subject: [PATCH] [#11912] Fix missing close on Jar InputStream in Plugin --- .../bootstrap/java9/module/JarFileAnalyzer.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/agent-module/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/JarFileAnalyzer.java b/agent-module/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/JarFileAnalyzer.java index 63f3972b0aa0..ec9c594cf1e9 100644 --- a/agent-module/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/JarFileAnalyzer.java +++ b/agent-module/bootstraps/bootstrap-java9/src/main/java/com/navercorp/pinpoint/bootstrap/java9/module/JarFileAnalyzer.java @@ -95,13 +95,16 @@ public Providers apply(JarEntry jarEntry) { if (jarEntryName.indexOf('/', SERVICE_LOADER.length()) != -1) { return null; } - try { - InputStream inputStream = jarFile.getInputStream(jarEntry); + List serviceImplClassName = readServiceProviderConfig(jarEntry); + String serviceClassName = jarEntryName.substring(SERVICE_LOADER.length()); + return new Providers(serviceClassName, serviceImplClassName); + } + + private List readServiceProviderConfig(JarEntry jarEntry) { + try (InputStream inputStream = jarFile.getInputStream(jarEntry)) { ServiceDescriptorParser parser = new ServiceDescriptorParser(); - List serviceImplClassName = parser.parse(inputStream); - String serviceClassName = jarEntryName.substring(SERVICE_LOADER.length()); - return new Providers(serviceClassName, serviceImplClassName); + return parser.parse(inputStream); } catch (IOException e) { throw new IllegalStateException(jarFile.getName() + " File read fail ", e); }