How to deal w/ module-info.java existing
See original GitHub issueHi
We solved the bootstrap instrumentation in all JDKs. Now I want to dig more for JDK 9 - 12. As the module introduced in JDK, although most people don’t use today, I want the plugin mechanism ready to go.
I write a simple test, Main.java
public class Main {
public static void main(String[] args) throws IOException {
URL obj = new URL("http://www.baidu.com");
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
System.out.println(con.getRequestMethod());
// con.setChunkedStreamingMode(0);
//add request header
int responseCode = con.getResponseCode();
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
}
Empty module-info.java
module JRE.test {
}
After I installed the agent, in JDK 9 -12, it shows the following error
- Do bootstrap instrumentation
ERROR 2019-08-01 14:24:38:322 main SkyWalkingAgent : SkyWalking agent inject bootstrap instrumentation failure. Shutting down.
java.lang.UnsupportedOperationException: Could not access Unsafe class: sun.misc.Unsafe
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$Unavailable.initialize(ClassInjector.java:2033)
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.injectRaw(ClassInjector.java:1765)
at org.apache.skywalking.apm.agent.core.plugin.bootstrap.BootstrapInstrumentBoost.inject(BootstrapInstrumentBoost.java:102)
at org.apache.skywalking.apm.agent.SkyWalkingAgent.premain(SkyWalkingAgent.java:103)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:500)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:512)
- Do simple Main function instrumentation
DEBUG 2019-08-01 14:26:48:650 main SkyWalkingAgent : On Transformation class a.Main.
Exception in thread "main" java.lang.ExceptionInInitializerError
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at JRE.test/a.Main.<clinit>(Main.java)
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.Nexus.initialize(Nexus.java:137)
... 5 more
Caused by: java.lang.UnsupportedOperationException: Cannot get package using reflection: sun.misc.Unsafe
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Initializable$Unavailable.getPackage(ClassInjector.java:418)
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.injectRaw(ClassInjector.java:220)
at org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:112)
at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$InitializationStrategy$SelfInjection$Dispatcher$InjectingInitializer.onLoad(AgentBuilder.java:3143)
... 10 more
How should I avoid these? And make the plugin works if user turns module definition on?
Issue Analytics
- State:
- Created 4 years ago
- Comments:33 (12 by maintainers)
Top Results From Across the Web
Where to place module-info.java using Java 9? - Stack Overflow
To answer your specific questions: Place module declaration ( module-info.java ) into the project's source root directory (e.g. src/main/java ).
Read more >Java Modules - Jenkov.com
A Java module is a packaging mechanism that enables you to package a Java application or Java API as a separate Java module....
Read more >Understanding Java 9 Modules - Oracle
In this article, I introduce the Java 9 Platform Module System (JPMS), the most important new software engineering technology in Java since its...
Read more >Java 9 Modules - A guide to understanding them - Xperti
Modules in Java require a Java module descriptor named module-info.java. It must be located in the module root directory. The module descriptor ...
Read more >A Guide to Java 9 Modularity - Baeldung
class file included in the assembled JAR. Automatic Modules – We can include unofficial modules by adding existing JAR files to the module...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think that I will include a workaround for the unavailability of jdk.unsupported and make a release after that. I have also registered an issue with OpenJDK for this phenomenon: https://bugs.openjdk.java.net/browse/JDK-8229121
I’d say that I release 1.10.1 some time at the end of August.
Glad it works for you. I just released a new version.