diff --git a/instrumentation/runtime-telemetry/runtime-telemetry-java8/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/runtimemetrics/java8/JarAnalyzer.java b/instrumentation/runtime-telemetry/runtime-telemetry-java8/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/runtimemetrics/java8/JarAnalyzer.java index ad3f2ea8cda0..9f48d5610f9e 100644 --- a/instrumentation/runtime-telemetry/runtime-telemetry-java8/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/runtimemetrics/java8/JarAnalyzer.java +++ b/instrumentation/runtime-telemetry/runtime-telemetry-java8/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/runtimemetrics/java8/JarAnalyzer.java @@ -18,6 +18,7 @@ import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsUtil; import io.opentelemetry.sdk.common.Clock; import io.opentelemetry.sdk.internal.DaemonThreadFactory; +import java.io.File; import java.io.IOException; import java.lang.instrument.ClassFileTransformer; import java.net.URI; @@ -131,6 +132,22 @@ private void handle(ProtectionDomain protectionDomain) { return; } + // Payara 5 and 6 have url with file protocol that fail on openStream with + // java.io.IOException: no entry name specified + // at + // java.base/sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:160) + // To avoid this here we recreate the URL when it points to a file. + if ("file".equals(archiveUrl.getProtocol())) { + try { + File archiveFile = new File(archiveUrl.toURI().getSchemeSpecificPart()); + if (archiveFile.exists() && archiveFile.isFile()) { + archiveUrl = archiveFile.toURI().toURL(); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Unable to normalize location URL: " + archiveUrl, e); + } + } + // Only code locations with .jar and .war extension should make it here toProcess.add(archiveUrl); }