Implement getContentLenth for InternalJarUrlHandler
MODIFY
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InternalJarUrlHandler.java
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InternalJarUrlHandler.java
@@ -55,7 +55,7 @@ public class InternalJarUrlHandler extends URLStreamHandler {
// This is called by the SecureClassLoader trying to obtain permissions
// nullInputStream() is not available until Java 11
- return new InternalJarUrlConnection(url, new ByteArrayInputStream(new byte[0]));
+ return new InternalJarUrlConnection(url, new ByteArrayInputStream(new byte[0]), 0);
}
// believe it or not, we're going to get called twice for this,
// and the key will be a new object each time.
@@ -76,7 +76,8 @@ public class InternalJarUrlHandler extends URLStreamHandler {
// so dismiss cache after a hit
cache = NULL;
}
- return new InternalJarUrlConnection(url, bootstrapJarFile.getInputStream(pair.entry));
+ return new InternalJarUrlConnection(
+ url, bootstrapJarFile.getInputStream(pair.entry), pair.entry.getSize());
}
private String getResourcePath(String filename) {
@@ -95,10 +96,12 @@ public class InternalJarUrlHandler extends URLStreamHandler {
private static class InternalJarUrlConnection extends URLConnection {
private final InputStream inputStream;
+ private final long contentLength;
- private InternalJarUrlConnection(URL url, InputStream inputStream) {
+ private InternalJarUrlConnection(URL url, InputStream inputStream, long contentLength) {
super(url);
this.inputStream = inputStream;
+ this.contentLength = contentLength;
}
@Override
@@ -116,6 +119,11 @@ public class InternalJarUrlHandler extends URLStreamHandler {
// No permissions needed because all classes are in memory
return null;
}
+
+ @Override
+ public long getContentLengthLong() {
+ return contentLength;
+ }
}
private static class FileNotInInternalJar extends IOException {

Implement getContentLenth for InternalJarUrlHandler (#2692)