diff --git a/telemetry/src/main/java/datadog/telemetry/dependency/DependencyResolver.java b/telemetry/src/main/java/datadog/telemetry/dependency/DependencyResolver.java index 1397ad7ec29..c4b0842a831 100644 --- a/telemetry/src/main/java/datadog/telemetry/dependency/DependencyResolver.java +++ b/telemetry/src/main/java/datadog/telemetry/dependency/DependencyResolver.java @@ -75,17 +75,18 @@ static List extractDependenciesFromJar(File jar) { } List dependencies = Collections.emptyList(); - try (JarFile file = new JarFile(jar, false /* no verify */); - InputStream is = Files.newInputStream(jar.toPath())) { + try (JarFile file = new JarFile(jar, false /* no verify */)) { // Try to get from maven properties dependencies = Dependency.fromMavenPom(file); // Try to guess from manifest or file name if (dependencies.isEmpty()) { - Manifest manifest = file.getManifest(); - dependencies = - Collections.singletonList(Dependency.guessFallbackNoPom(manifest, jar.getName(), is)); + try (InputStream is = Files.newInputStream(jar.toPath())) { + Manifest manifest = file.getManifest(); + dependencies = + Collections.singletonList(Dependency.guessFallbackNoPom(manifest, jar.getName(), is)); + } } } catch (IOException e) { log.debug("unable to read jar file {}", jar, e);