From b1b1615926fd50a287d645166077d1f2b78160ce Mon Sep 17 00:00:00 2001 From: Weiyi Liu Date: Tue, 7 Jan 2020 10:01:25 +0800 Subject: [PATCH] Close inputstream. (#4184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: kezhenxu94 Co-authored-by: 吴晟 Wu Sheng --- .../apm/agent/core/remote/AgentIDDecorator.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AgentIDDecorator.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AgentIDDecorator.java index 58d6b9c26..daa8b4cbd 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AgentIDDecorator.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AgentIDDecorator.java @@ -51,14 +51,15 @@ public class AgentIDDecorator implements ChannelDecorator { Enumeration resources = AgentIDDecorator.class.getClassLoader().getResources(JarFile.MANIFEST_NAME); while (resources.hasMoreElements()) { URL url = resources.nextElement(); - InputStream is = url.openStream(); - if (is != null) { - Manifest manifest = new Manifest(is); - Attributes mainAttribs = manifest.getMainAttributes(); - String projectName = mainAttribs.getValue("Implementation-Vendor-Id"); - if (projectName != null) { - if ("org.apache.skywalking".equals(projectName)) { - version = mainAttribs.getValue("Implementation-Version"); + try (InputStream is = url.openStream()) { + if (is != null) { + Manifest manifest = new Manifest(is); + Attributes mainAttribs = manifest.getMainAttributes(); + String projectName = mainAttribs.getValue("Implementation-Vendor-Id"); + if (projectName != null) { + if ("org.apache.skywalking".equals(projectName)) { + version = mainAttribs.getValue("Implementation-Version"); + } } } }