问题
JaCoCo stopped working after setting the log4j.configurationFactory
system property.
java.lang.reflect.InvocationTargetException
FATAL ERROR in native method: processing of -javaagent failed
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.lang.Class.getField(Class.java:1703)
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
Exception in thread "main"
I've read about an error like that with JaCoCo and JDK 1.8, but it was already solved in JaCoCo 0.7.7.
The VM arguments are defined like following:
-Dlog4j.configurationFactory=mytest.CustomConfigurationFactory
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dcom.sun.management.jmxremote.rmi.port=9090
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
-javaagent:/path/jacocoagent.jar=destfile=C:/TEMP/jacoco.exec,jmx=true
I'm using:
- JaCoCo 0.7.7
- Log4j 2.8.1
- JDK 1.8.0_102
Does anyone know how to solve it?
回答1:
As was answered in JaCoCo users mailing list :
There seems to be a real problem in interactions between JaCoCo (up to the latest version that is 0.7.9 as of today), JMX and Logging when Log4j JDK Logging Adapter is used and JaCoCo agent registers JMX MBean. Deeper investigations would require some time, in the meantime
either JaCoCo agent should be configured to not register JMX MBean, i.e. without
jxm=true
or equivalently withjxm=false
(-javaagent:jacocoagent.jar=jmx=false
), and should be noted that JMX is not the only option for remote connections to JaCoCo agent - have a look atoutput=tcpserver
andoutput=tcpclient
either Log4j JDK Logging Adapter shouldn't be used, i.e. without
‑Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
Update
And here is a ticket for a fix on JaCoCo side that explains what happens - https://github.com/jacoco/jacoco/issues/531
来源:https://stackoverflow.com/questions/43893596/jacoco-stopped-working-after-setting-the-log4j-configurationfactory-system-prope