1414 * limitations under the License.
1515 */
1616
17- package io .opentelemetry .instrumentation . auto . api ;
17+ package io .opentelemetry .javaagent . bootstrap ;
1818
1919import java .io .ByteArrayInputStream ;
2020import java .io .File ;
3131import org .slf4j .Logger ;
3232import org .slf4j .LoggerFactory ;
3333
34- // TODO remove this from api
3534public class InternalJarURLHandler extends URLStreamHandler {
3635
3736 private static final Logger log = LoggerFactory .getLogger (InternalJarURLHandler .class );
3837
39- private static final WeakReference <Pair < String , JarEntry > > NULL = new WeakReference <>(null );
38+ private static final WeakReference <ResolvedJarEntry > NULL = new WeakReference <>(null );
4039
4140 private final String name ;
4241 private final FileNotInInternalJar notFound ;
4342 private final JarFile bootstrapJarFile ;
4443
45- private WeakReference <Pair < String , JarEntry > > cache = NULL ;
44+ private WeakReference <ResolvedJarEntry > cache = NULL ;
4645
4746 public InternalJarURLHandler (String internalJarFileName , URL bootstrapJarLocation ) {
4847 name = internalJarFileName ;
@@ -71,11 +70,11 @@ protected URLConnection openConnection(URL url) throws IOException {
7170 }
7271 // believe it or not, we're going to get called twice for this,
7372 // and the key will be a new object each time.
74- Pair < String , JarEntry > pair = cache .get ();
75- if (null == pair || !filename .equals (pair .getLeft () )) {
73+ ResolvedJarEntry pair = cache .get ();
74+ if (null == pair || !filename .equals (pair .filename )) {
7675 JarEntry entry = bootstrapJarFile .getJarEntry (getResourcePath (filename ));
7776 if (null != entry ) {
78- pair = Pair . of (filename , entry );
77+ pair = new ResolvedJarEntry (filename , entry );
7978 // the cache field is not volatile as a performance optimization
8079 // in the rare event this write is not visible to another thread,
8180 // it just means the same work is recomputed but does not affect consistency
@@ -88,7 +87,7 @@ protected URLConnection openConnection(URL url) throws IOException {
8887 // so dismiss cache after a hit
8988 cache = NULL ;
9089 }
91- return new InternalJarURLConnection (url , bootstrapJarFile .getInputStream (pair .getRight () ));
90+ return new InternalJarURLConnection (url , bootstrapJarFile .getInputStream (pair .entry ));
9291 }
9392
9493 private String getResourcePath (String filename ) {
@@ -141,4 +140,14 @@ public Throwable fillInStackTrace() {
141140 return this ;
142141 }
143142 }
143+
144+ private static class ResolvedJarEntry {
145+ private final String filename ;
146+ private final JarEntry entry ;
147+
148+ private ResolvedJarEntry (String filename , JarEntry entry ) {
149+ this .filename = filename ;
150+ this .entry = entry ;
151+ }
152+ }
144153}
0 commit comments