Wildfly and ByteBuddy Agent

404 views
Skip to first unread message

Laurent Bertrand

unread,
Feb 15, 2016, 11:43:21 AM2/15/16
to Byte Buddy
Hi,

I am trying to achieve the following with an EART deployed on Wildfly. Some of the classes in the EAR are declaring some public static method that I would like to intercept and delegate to another class I am writing so that I can do something different without changing the original class!

So my though was to use ByteBuddy to create an agent that will intercept the loading of the specific class and transform it so that any of the public static method is sent to my own class.

I then modify the startup of Wildfly to add the loading of my agent with -javaagent and I can see in the logs that the class I want to change is correctly intercepted and delegated to my own class.

BUT, it fails with NoClassDefFoundError on other classes which are part of the EAR but not part of my agent... I am thinking that it is because the classloader of the agent can't delegate to the jboss module classloader therefore not access the classes in the EAR?

Does anyone has any idea how to achieve this? I can't imagine I have to put all of my EAR classes into the jar of my agent!

Exception stack trace:
java.lang.NoClassDefFoundError: javax/persistence/EntityManager
^[[0m^[[31m13:53:05,797 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods0(Native Method)
^[[0m^[[31m13:53:05,797 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods(Class.java:1975)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.description.method.MethodList$ForLoadedType.<init>(MethodList.java:90)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.description.type.TypeDescription$ForLoadedType.getDeclaredMethods(TypeDescription.java:7409)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.implementation.MethodDelegation$MethodContainer$ForExplicitMethods.ofStatic(MethodDelegation.java:1043)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.implementation.MethodDelegation.to(MethodDelegation.java:249)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.implementation.MethodDelegation.to(MethodDelegation.java:228)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at myPackage.MyAgent.lambda$premain$0(EntityPeersAgent.java:58)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.agent.builder.AgentBuilder$Transformer$Compound.transform(AgentBuilder.java:547)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:4309)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:4609)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at java.lang.ClassLoader.defineClass1(Native Method)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.Module.loadModuleClass(Module.java:560)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
^[[0m^[[31m13:53:05,798 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
^[[0m^[[31m13:53:05,799 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
^[[0m^[[31m13:53:05,799 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
^[[0m^[[31m13:53:05,799 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods0(Native Method)
^[[0m^[[31m13:53:05,799 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
^[[0m^[[31m13:53:05,799 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods(Class.java:1975)

Laurent Bertrand

unread,
Feb 15, 2016, 5:39:17 PM2/15/16
to Byte Buddy
I managed to bypass this issue for now by using Object instead of specific classes and not throwing exception and can't see any errors in the log coming from my agent listener... It seem to instantiate my peer class.

But when the application call a public static method on the original class, the peer class is not called, only the original class.

I am sure I am missing something and my knowledge how all of this work related to also a full J2EE container software like Wilfly.

Anyone has example of achieving what I am trying to do? Basically delegate public static method call of an original class to a new one, the original class being part of an EAR deployed in wildfly?

My code for the agent:
/code
new AgentBuilder.Default()
.with(new AgentBuilder.Listener() {

@Override
public void onTransformation(TypeDescription typeDescription, DynamicType dynamicType) {
System.out.println("*** AGENT: Transformed - " + typeDescription + ", type = " + dynamicType);
}

@Override
public void onIgnored(TypeDescription typeDescription) {
System.out.println("*** AGENT: Ignored - " + typeDescription);
}

@Override
public void onError(String s, Throwable throwable) {
System.out.println("*** AGENT: Error - " + s + ", " + throwable.getMessage());
throwable.printStackTrace();
}

@Override
public void onComplete(String s) {
System.out.println("*** AGENT: Completed - " + s);
}
})
.type(matchingTypes)
.transform((builder, type) -> {
System.out.println("*** AGENT: Transform - " + type);
Class<?> peerClass = peerClassPerType.get(type.getCanonicalName());
if (null != peerClass) {
System.out.println("*** AGENT: Transform - Peer Class is " + peerClass);
builder.method(ElementMatchers.isStatic())
.intercept(MethodDelegation.to(peerClass));
}
return builder;
}
)
.installOn(inst);
/code

Rafael Winterhalter

unread,
Feb 16, 2016, 4:38:05 AM2/16/16
to Laurent Bertrand, Byte Buddy
I have a theory. When you install an agent on an app server, here is
what happens:

The Java agent is loaded as if it was put on the class path, i.e. it
is loaded by the system class loader. For an average Java application,
this is where the application itself lives as well. On an application
server, the application itself is however loaded by an application
class loader that encapsulates the application's classes. This is what
makes the app undeployable. These application class loaders are
usually child-first, i.e. they look for a class that is encapsulated
within the ear before querying its parent as for example the system
class loader.

Within application servers, this introduces the following challange:
1. The instrumented class is loaded by the application class loader.
2. The agent is loaded by the system class loader.
2. The agent needs to resolve another class on a class loader that is
"foreign", i.e. only becomes visible during instrumentation.

I believe that your "peerClass" is loaded on the system class loader
but supposed to be loaded by the application class loader. This you
can easily validate by "peerClass.getClassLoader ==
ClassLoader.getSystemClassLoader()". This is not the failure of the
class, but the target needs to be resolved during instrumentation. In
this context, I identified a lack in the API, this class loader should
be provided by Byte Buddy.

I just pushed a change to Byte Buddy where the builder API receives a
third argument, the class loader of the instrumented class. What you
should normally do would be to look up the delegation target from this
class loader. You can clone and builld Byte Buddy from head to see if
this works for you. You would need to resolve the class as such:

Class<?> peerClass =
classLoader.findClass(peerClassPerType.get(type.getCanonicalName()));

Does this work for you?
Cheers, Rafael
> --
> You received this message because you are subscribed to the Google Groups
> "Byte Buddy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to byte-buddy+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Laurent Bertrand

unread,
Feb 16, 2016, 5:05:26 AM2/16/16
to Byte Buddy, laurent....@gmail.com
Thanks for this quick response...

I am trying your changes now, but findClass is protected in the ClassLoader class... So I am using loadClass, is this the same?

Laurent Bertrand

unread,
Feb 16, 2016, 5:17:37 AM2/16/16
to Byte Buddy, laurent....@gmail.com
Got a new error now using loadClass instead of findClass

[[0m^[[0m10:09:48,753 INFO  [stdout] (MSC service thread 1-2) *** AGENT: Error - theClassToInstrument, null
^[[0m^[[31m10:09:48,753 ERROR [stderr] (MSC service thread 1-2) java.lang.AbstractMethodError
^[[0m^[[31m10:09:48,753 ERROR [stderr] (MSC service thread 1-2)         at net.bytebuddy.agent.builder.AgentBuilder$Transformer$Compound.transform(AgentBuilder.java:547)
^[[0m^[[31m10:09:48,753 ERROR [stderr] (MSC service thread 1-2)         at net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:4309)
^[[0m^[[31m10:09:48,753 ERROR [stderr] (MSC service thread 1-2)         at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:4609)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at java.lang.ClassLoader.defineClass1(Native Method)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.Module.loadModuleClass(Module.java:560)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at java.lang.Class.getDeclaredMethods0(Native Method)
^[[0m^[[31m10:09:48,754 ERROR [stderr] (MSC service thread 1-2)         at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
^[[0m^[[31m10:09:48,755 ERROR [stderr] (MSC service thread 1-2)         at java.lang.Class.getDeclaredMethods(Class.java:1975)
^[[0m^[[31m10:09:48,755 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65)
^[[0m^[[31m10:09:48,755 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
^[[0m^[[31m10:09:48,755 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
^[[0m^[[31m10:09:48,755 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:107)
^[[0m^[[31m10:09:48,759 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:92)
^[[0m^[[31m10:09:48,759 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
^[[0m^[[31m10:09:48,760 ERROR [stderr] (MSC service thread 1-2)         at java.lang.Thread.run(Thread.java:745)

Rafael Winterhalter

unread,
Feb 16, 2016, 5:38:46 AM2/16/16
to Laurent Bertrand, Byte Buddy
Hei Laurent,
findClass is correct, my bad. About the AbstractMethodError: I think
you did not recompile all your classes, the error indicates that you
still use an old version of the transform method with two arguments
instead of three.
Cheers, Rafael

Laurent Bertrand

unread,
Feb 16, 2016, 5:51:00 AM2/16/16
to Byte Buddy, laurent....@gmail.com
You were right, I left a link to version 1.2.1 embedded in my agent jar...

But now I can see a lot of 
[[0m^[[31m10:46:52,592 ERROR [stderr] (ServerService Thread Pool -- 65) java.lang.NoClassDefFoundError: Could not initialize class net.bytebuddy.pool.TypePool$LazyFacade
^[[0m^[[31m10:46:52,592 ERROR [stderr] (ServerService Thread Pool -- 65)        at net.bytebuddy.agent.builder.AgentBuilder$BinaryLocator$Default.typePool(AgentBuilder.java:643)
^[[0m^[[31m10:46:52,592 ERROR [stderr] (ServerService Thread Pool -- 65)        at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:4531)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at java.lang.ClassLoader.defineClass1(Native Method)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.Module.loadModuleClass(Module.java:560)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
^[[0m^[[31m10:46:52,593 ERROR [stderr] (ServerService Thread Pool -- 65)        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.j

Any idea? 

Rafael Winterhalter

unread,
Feb 16, 2016, 6:53:04 AM2/16/16
to Laurent Bertrand, Byte Buddy
Hei Laurent, this still looks a bit dodgy. I do not see how
initializing LazyFacade can fail, there is literaly nothing to do. Are
you sure you are no longer mixing versions?

Laurent Bertrand

unread,
Feb 16, 2016, 7:13:24 AM2/16/16
to Byte Buddy, laurent....@gmail.com
Remove the 1.2.1 jar from everywhere so the only version I have is 1.2.2-dep jar...

And for every class the agent sees I have the same error:
^[[0m^[[31m12:03:40,098 ERROR [stderr] (ServerService Thread Pool -- 143) java.lang.NoClassDefFoundError: Could not initialize class net.bytebuddy.pool.TypePool$LazyFacade
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at net.bytebuddy.agent.builder.AgentBuilder$BinaryLocator$Default.typePool(AgentBuilder.java:643)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:4531)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.lang.ClassLoader.defineClass1(Native Method)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.Module.loadModuleClass(Module.java:560)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.cesecore.util.CryptoProviderTools.installBCProvider(CryptoProviderTools.java:122)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.ejbca.ui.web.admin.configuration.StartServicesServlet.ejbcaInit(StartServicesServlet.java:197)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.ejbca.ui.web.admin.configuration.StartServicesServlet.init(StartServicesServlet.java:164)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:230)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:131)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:511)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:101)
^[[0m^[[31m12:03:40,099 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at java.lang.Thread.run(Thread.java:745)
^[[0m^[[31m12:03:40,100 ERROR [stderr] (ServerService Thread Pool -- 143)       at org.jboss.threads.JBossThread.run(JBossThread.java:320)

Maybe the problem is how I package / deploy my stuff:
1. I created a jar for the agent which embed byte buddy jar and contains my agent with the premain, as well as my peer classes
2. I added running this jar to wildfly by setting the -javagent at startup
3. I also embed the same jar inside wildfly EAR under the lib directory

Maybe I need to split the files in different jar and put them at different places in EAR and or wildfly!

Rafael Winterhalter

unread,
Feb 16, 2016, 7:21:23 AM2/16/16
to Laurent Bertrand, Byte Buddy
What strikes me is that the error is triggered from
net.bytebuddy.agent.builder.AgentBuilder$BinaryLocator$Default. This
should only happen if the library is not fully packaged. I currently
deploy a new version to JCenter and Maven Central; maybe that helps.

The setup that you provide sounds correct. The agent and Byte Buddy
should be on the class path. The peer classes should be part of the
application if they reference any application classes directly.
Otherwise, the class path is fine.

Laurent Bertrand

unread,
Feb 16, 2016, 8:03:42 AM2/16/16
to Byte Buddy, laurent....@gmail.com
I tried to rearrange my classes a little bit but still the same error!

Basically, I have now 2 jars:
1. one for the agent which has no dependencies on anything from the app directly (use strings to find my classes as per point above). So I package this jar with embedded byte buddy library in it and pass it to wildfly as a -javaagent
2. all of my peer classes are in another jar which I embed in my EAR so that it is at the same level

/code
[[0m^[[0m12:58:33,757 INFO  [stdout] (MSC service thread 1-4) *** AGENT: Error - org.cesecore.certificates.ca.CAData, Could not initialize class net.bytebuddy.pool.TypePool$LazyFacade
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4) java.lang.NoClassDefFoundError: Could not initialize class net.bytebuddy.pool.TypePool$LazyFacade
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.agent.builder.AgentBuilder$BinaryLocator$Default.typePool(AgentBuilder.java:643)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:4531)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at java.lang.ClassLoader.defineClass1(Native Method)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:353)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:432)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:269)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:77)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.Module.loadModuleClass(Module.java:560)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
^[[0m^[[31m12:58:33,757 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods0(Native Method)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Class.getDeclaredMethods(Class.java:1975)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:65)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:107)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:92)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
^[[0m^[[31m12:58:33,758 ERROR [stderr] (MSC service thread 1-4)         at java.lang.Thread.run(Thread.java:745)
/code

Let me know when the new bytebuddy can be downloaded as a jar so I can try with your build version

Rafael Winterhalter

unread,
Feb 16, 2016, 8:17:44 AM2/16/16
to Laurent Bertrand, Byte Buddy
The new version is already on JCenter and you can also download them
directly from Bintray. 1.2.2 is also currently synchronizing to Maven
Central.

I am pretty much convinced that this is a problem with your built even
though I do not quite understand what happens. TypePool$LazyFacade
does not define a class initializer, there should not be a problem
loading this class.

Let me know if anything changes!

Laurent Bertrand

unread,
Feb 16, 2016, 8:26:24 AM2/16/16
to Byte Buddy, laurent....@gmail.com
Many thanks for your support!

I downloaded the version from bintray and can't see any exceptions anymore.

I also do not see any exception loading other classes part of the application in my Peer class so your changes in 1.2.2 did allow me to load my peer class using the right classloader.

That is great.

But for some reason, even if my peer class seems to have been instantiated properly:

[[0m^[[0m13:17:05,132 INFO  [stdout] (MSC service thread 1-8) *** AGENT: Transform - class orignalClass
^[[0m^[[0m13:17:05,134 INFO  [stdout] (MSC service thread 1-8) *** AGENT: SystemClassLoader? false
^[[0m^[[0m13:17:05,134 INFO  [stdout] (MSC service thread 1-8) *** AGENT: Transform - Peer Class is class peerClass
^[[0m^[[0m13:17:05,303 INFO  [stdout] (MSC service thread 1-8) *** AGENT: Transformed - class orignalClass, type = DynamicType.Default.Unloaded{typeDescription='class orignalClass', binaryRepresentation=<11426 bytes>, typeInitializer=LoadedTypeInitializer.NoOp.INSTANCE, auxiliaryTypes=[]}
^[[0m^[[0m13:17:05,304 INFO  [stdout] (MSC service thread 1-8) *** AGENT: Completed - orignalClass

I cannot see it being called later on at all instead of the originalClass!

This is my transform method:
.transform((builder, type, classLoader) -> {
System.out.println("*** AGENT: All loaded classes - " + Arrays.toString(inst.getAllLoadedClasses()));

System.out.println("*** AGENT: Transform - " + type);
            //Class<?> peerClass = peerClassPerType.get(type.getCanonicalName());
Class<?> peerClass = null;
try {
peerClass = classLoader.loadClass(peerClassPerType.get(type.getCanonicalName()));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Error loading peer class", e);
}
if (null != peerClass) {
System.out.println("*** AGENT: SystemClassLoader? " + (peerClass.getClassLoader() == ClassLoader.getSystemClassLoader()));

System.out.println("*** AGENT: Transform - Peer Class is " + peerClass);
builder.method(ElementMatchers.isStatic())
.intercept(MethodDelegation.to(peerClass));
}
return builder;
}
)

Is this correct for delegating any of the public static method on the original class to the peer class?

Looking at the log, I can also see, that for some reason, my original class is used before I can see the agent transform call!
>> >> >> >>> >...

Rafael Winterhalter

unread,
Feb 17, 2016, 1:25:51 AM2/17/16
to Laurent Bertrand, Byte Buddy

Your code looks correct. This should create a delegation of all static (public or not) methods to your peer class.

Since your log is triggered, your classes should be redefined. Are you sure that the delegation is not made? Does your agent work in a test scenario without WildFly?

Cheers, Rafael

--
Reply all
Reply to author
Forward
0 new messages