The provided code intercepts the connect method of the HttpURLConnection class in Java 8. However, when attempting to run the same code with Java 17, it results in an error provided below.
please provide any solutions or suggestion.
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:62)
at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:57)
at java.base/java.net.URL.openConnection(URL.java:1094)
at com.JavaAgent.Agent.Test.main(Test.java:26)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.net.www.protocol.http.HttpURLConnection.(HttpURLConnection.java:435)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at net.bytebuddy.dynamic.Nexus.initialize(Nexus.java:143)
... 9 more
Caused by: java.lang.IllegalStateException: Cannot load injected class
at net.bytebuddy.dynamic.loading.ClassInjector$UsingInstrumentation.injectRaw(ClassInjector.java:2498)
at net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:118)
at net.bytebuddy.agent.builder.AgentBuilder$InitializationStrategy$SelfInjection$Dispatcher$InjectingInitializer.onLoad(AgentBuilder.java:3855)
... 14 more
Caused by: java.lang.ClassNotFoundException: sun/net/www/protocol/http/HttpURLConnection$auxiliary$vcxnSSGw
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at net.bytebuddy.dynamic.loading.ClassInjector$UsingInstrumentation.injectRaw(ClassInjector.java:2487)
... 16 more
I assume this has to do with the module system preresolving names and not finding the new class. I would avoid auxiliary classes in such injection and rather use Advice to address such instrumentation.
The provided code intercepts the connect method of the HttpURLConnection class in Java 8. However, when attempting to run the same code with Java 17, it results in an error provided below. please provide any solutions or suggestion.
CODE :
ERROR :
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended Exception in thread "main" java.lang.ExceptionInInitializerError at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:62) at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:57) at java.base/java.net.URL.openConnection(URL.java:1094) at com.JavaAgent.Agent.Test.main(Test.java:26) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at java.base/sun.net.www.protocol.http.HttpURLConnection.(HttpURLConnection.java:435)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at net.bytebuddy.dynamic.Nexus.initialize(Nexus.java:143)
... 9 more
Caused by: java.lang.IllegalStateException: Cannot load injected class
at net.bytebuddy.dynamic.loading.ClassInjector$UsingInstrumentation.injectRaw(ClassInjector.java:2498)
at net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:118)
at net.bytebuddy.agent.builder.AgentBuilder$InitializationStrategy$SelfInjection$Dispatcher$InjectingInitializer.onLoad(AgentBuilder.java:3855)
... 14 more
Caused by: java.lang.ClassNotFoundException: sun/net/www/protocol/http/HttpURLConnection$auxiliary$vcxnSSGw
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at net.bytebuddy.dynamic.loading.ClassInjector$UsingInstrumentation.injectRaw(ClassInjector.java:2487)
... 16 more