Tomcat elastic-apm-agent, and application version in context path fails on ProtectionDomain

I'm currently configuring a Java app in tomcat7 to use elastic-apm-agent.
Java - elastic-apm-agent-1.6.1
Tomcat is running on a linux ec2-instance, its' currently at tomcat-7.0.94.

I've copied the agent in, added the configuration to my tomcat7.conf, and started the tomcat service, and in catalina.out i get:
2019-06-10 07:38:47.860 [localhost-startStop-1] ERROR
co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers - Cannot read implementation
version based on ProtectionDomain ProtectionDomain
(file:/var/lib/tomcat7/webapps/portal%23%23k000226/WEB-INF/lib/httpclient-4.5.2.jar )
context: /portal##k000226
delegate: false
----------> Parent Classloader:

 <no principals> (
 ("" "/var/lib/tomcat7/webapps/portal##k000226/WEB-INF/lib/httpclient-4.5.2.jar" "read")

If i remove the application version from the deployed war, this problem goes away. It seems like the filename is corrupted when checking for ProtectionDomain? Is there any other way I can get this to work and still retain the application version in the context path?

Hi and welcome to the forum :slight_smile:

I think I better change the behavior so that if version is not found, we default to instrument, so we at least attempt (in this case there will be no harm in any case).

Still, can you please provide the full related log entry? The log section you added should be followed by an Exception and stack trace.

Ok yep I can get that tomorrow, time zone beat me today!
The bit that didn’t format above with the same file but %23 instead of hash where it said protectiondomain I think is the root cause, it looks to have URL encoded a file path, that’s not right I think? Certainly if I try to ‘ls’ that path, the shell can’t locate it....

It may very well be the case, so decoding is an optional solution. I just want to see what we actually logged, as it should direct us.

2019-06-10T07:38:11.439+1000: [CMS-concurrent-abortable-preclean-start]
2019-06-10 07:38:14.108 [localhost-startStop-1] ERROR co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers - Cannot read implementation version based on ProtectionDomain ProtectionDomain  (file:/var/lib/tomcat7/webapps/v4%23%23k000306/WEB-INF/lib/httpclient-4.5.6.jar <no signer certificates>)
  context: /v4##k000306^M
  delegate: false^M
----------> Parent Classloader:^M^M

 <no principals> (
 ("" "/var/lib/tomcat7/webapps/v4##k000306/WEB-INF/lib/httpclient-4.5.6.jar" "read")
) /var/lib/tomcat7/webapps/v4%23%23k000306/WEB-INF/lib/httpclient-4.5.6.jar (No such file or directory)
        at Method)
        at java.util.jar.JarFile.<init>(
        at java.util.jar.JarFile.<init>(
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.readImplementationVersionFromManifest(
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.access$100(
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers$2.matches(
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers$2.matches(
        at co.elastic.apm.agent.bci.ElasticApmAgent$4.matches(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.matches(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.resolve(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Compound.resolve(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.resolve(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$
        at Method)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(
        at sun.instrument.TransformerManager.transform(
        at sun.instrument.InstrumentationImpl.transform(
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
        at org.apache.http.impl.nio.client.HttpAsyncClients.createSystem(
        at org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory.<init>(
        at com.pds.common.http.AbstractHttpClient.<clinit>(
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
        at java.lang.reflect.Constructor.newInstance(
        at org.springframework.beans.BeanUtils.instantiateClass(

different app, same issue... (hence portal from above is now v4)
In case it is important - this is tomcat 7.0.94...

Thanks for log. It is indeed the encoding.
Please test this snapshot and see if it fixes the problem.

I'd love to test it, but the link doesn't seem to be valid?

I tried the snapshot link and got elastic-apm-agent-1.6.2-20190611.093948-46.jar, but that didnt seem to include your fix, or didn't work if it did... Having a look at the code, i'd say it didn't include your fix...

I tried to build it but I'm using JDK8 so its not so simple :confused:



Sorry, corrupted link :man_facepalming:
Please try this one instead.
In any case, we will probably release 1.7.0 this week, which should fix this.

Hi Eyal,
Thanks for the new link - i tried that new snapshot and it's resolved the issue!



1 Like