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"); + } } } }