Closing metricsconfigs.txt
MODIFY
dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java
dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java
@@ -139,13 +139,13 @@ public class JMXFetch {
}
private static List<String> getInternalMetricFiles() {
- try {
- final InputStream metricConfigsStream =
- JMXFetch.class.getResourceAsStream("metricconfigs.txt");
+ final InputStream metricConfigsStream = JMXFetch.class.getResourceAsStream("metricconfigs.txt");
if (metricConfigsStream == null) {
log.debug("metricconfigs not found. returning empty set");
return Collections.emptyList();
- } else {
+ }
+
+ try {
final String configs = IOUtils.toString(metricConfigsStream, StandardCharsets.UTF_8);
final String[] split = configs.split("\n");
final List<String> result = new ArrayList<>(split.length);
@@ -167,10 +167,11 @@ public class JMXFetch {
}
}
return result;
- }
} catch (final IOException e) {
log.debug("error reading metricconfigs. returning empty set", e);
return Collections.emptyList();
+ } finally {
+ IOUtils.closeQuietly(metricConfigsStream);
}
}

Closing metricsconfigs.txt