Fwd: Using java.sql.Time in an Agent?
Alan Bateman
Alan.Bateman at oracle.com
Fri Jun 9 15:57:42 UTC 2017
On 09/06/2017 16:01, Todd West wrote:
> I am currently running into an issue where a usage of java.sql.Time in an
> Agent prevents the agent from starting correctly when running on JDK 9.
> Here is the example I am testing with:
>
> https://github.com/AdoptOpenJDK/jdk9-jigsaw/tree/
> master/session-1-jigsaw-intro/01_Greetings
>
> I modified the run.sh to look like the following:
>
> java -javaagent:/path/to/my/agent.jar \
> --module-path mods \
> --module com.greetings/com.greetings.Main
>
> However, the JVM fails to start up due to simply trying to parse some JSON:
>
> java.lang.NoClassDefFoundError: java/sql/Time
> at com.google.gson.Gson.<init>(Gson.java:232)
> at com.google.gson.GsonBuilder.create(GsonBuilder.java:545)
> ...
The "Visibility" section of the java.lang.instrument spec explains this:
"The types visible to the agent class are the types visible to the
system class loader. They minimally include the types in packages
exported by java.base and java.instrument. Whether all platform classes
are visible or not will depend on the initial module or application."
The initial module in the example is "com.greetings" and so the modules
are that are resolved at startup are the modules that it recursively
enumerates (along with any service provider modules), plus
"java.instrument" because `-javaagent` is specified.
There isn't any support at this time to develop or deploy java agents as
modules. It has been prototyped and most of the issues are interactions
are understood, it's just too much to take on for Java SE 9.
Using `--add-modules java.sql` is the workaround. The alternative is to
trim down the dependences so that the agent only needs java.base and
java.instrument. This would allow the agent to be used in small run-time
images that don't have java.sql too.
-Alan
More information about the jigsaw-dev
mailing list