jolokia: Bug with partial shading of `org.json.simple` in `jolokia-jvm:1.7.2`

package org.jolokia.jvmagent.handler;
...
public class JolokiaHttpHandler implements HttpHandler {
    ...
    // org.json.simple.JSONAware
    private JSONAware executeGetRequest(ParsedUri parsedUri) {
        // org.jolokia.shaded.org.json.simple.JSONAware
        return requestHandler.handleGetRequest(...);
    }

Result

Class cast exception in runtime. Version 1.6.2, worked without problems.

Links

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Or, maybe evenbetter we just use jolokia-agent-jvm-2.0.0-javaagent.jar ? (this directly reflects the -javaagent options in the name and should reduce the confusion)

Naming is hard, but you are a winner here 😉 It’s now clear:

  • jolokia-agent part means it’s Jolokia Agent (similar to WAR and OSGi agents)
  • javaagent means it’s a Jolokia Agent to be used with -javaagent

Can’t be better and clearer 😉

M4 rather had what pre 1.7.0 had, because the history is:

  • 1.6.x - maven-assembly-plugin with <id>agent</id> in assembly descriptor - so we have -agent classifier
  • 1.7.x - maven-shade-plugin without classifier - so we have just jolokia-jvm-1.7.2.jar with shaded classes inside
  • 2.0.0.M4 - maven-shade-plugin with <shadedArtifactAttached>true</shadedArtifactAttached> and <shadedClassifierName>agent</shadedClassifierName>

So actually, the only concern I have is that jolokia-agent-jvm-2.0.0-agent.jar looks weird…

cc: @rhuss @tadayosi @apupier

Let me highlight the issue:

  • jolokia-support-spring uses classes from jolokia-agent-jvm and it can’t be changed (org.jolokia.support.spring.SpringJolokiaAgent extends org.jolokia.jvmagent.JolokiaServer)
  • before 1.7.0, jolokia agent was available in two forms:
    • with agent classifier (embedding shaded json library and some jolokia deps)
    • without agent classifier (just classes from the agent)
  • after 1.7.0, jolokia agent had only no-classifier version with shaded classes

The classifier change was related to change from maven-assembly-plugin to maven-shade-plugin (see e7ab408b). But also it broke (see this issue) jolokia-support-spring → jolokia-agent-jvm dependency, because before 1.7.0, jolokia-support-spring depended on no-classifier agent without shaded classes.

createDependencyReducedPom of maven-shade-plugin is the way to express dependencies better, because what’s available in Maven repo after deployment is the processed POM without the dependencies that were actually shaded.

The problem however occurs in IDE / non-IDE scenarios. In pure Maven build, the dependencies are used after shading, however in IDE it’s before shading (which isn’t even performed). Before Jolokia 1.7.0 it wasn’t a problem, because we’d have to specify explicit dependency on <classifier>agent</classifier> version of jolokia-jvm…

That’s why now jolokia-support-spring tests work in IDE, but fail in mvn with:

Exception in thread "jolokia-0" java.lang.NoSuchMethodError: 'org.jolokia.shaded.org.json.simple.JSONObject org.jolokia.server.core.http.HttpRequestHandler.handleThrowable(java.lang.Throwable)'
	at org.jolokia.jvmagent.handler.JolokiaHttpHandler.doHandle(JolokiaHttpHandler.java:184)
	at org.jolokia.jvmagent.handler.JolokiaHttpHandler.handle(JolokiaHttpHandler.java:109)
	at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:95)
	at jdk.httpserver/sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:82)
	at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:98)
	at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:852)
	at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:95)
	at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:819)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:842)

The solution would be to get back to pre 1.7.0 behavior and have jolokia-agent-jvm deployed in two flavors:

  • with agent classifier (and shaded classes)
  • without classifier

Then no Jolokia module should depend on the agent classified version and jolokia-agent-jvm-2.0.0-agent.jar (…) should be used as standalone agent, in which case no other Jolokia dependency should be present on classpath.

WDYT?