byte-buddy

Interception on constructor causes ClassNotFoundException

社会主义新天地 提交于 2020-01-02 10:18:58
问题 I'm trying to intercept constructors annotated with @Inject . That worked fine in the context of a small unit test. However in the context of a DI container like Spring it fails with a ClassNotFoundException . I managed to narrow down on the root cause. Calling getDeclaredConstructors on the instrumented class will trigger this exception. Interestingly enough, if we first create an instance of that class, the problem disappears. For example: public class InterceptConstructorTest { @Test

JUnit Test framework for Javaagent Instrumentation Framework

可紊 提交于 2020-01-02 08:06:27
问题 What are the standard ways for creating unit tests for code of a Java agent and instrumentation libraries. I have created a Java agent using the Byte Buddy framework for developing a profiler on top of a web applictaion and now i wanted to write JUnit test cases for this agent. 回答1: You can take inspiration from Byte Buddy's own unit tests for creating a Java agent. For this, declare a test dependency on the byte-buddy-agent module. That module includes a class that is capable of attaching a

SpringBoot 2.1.0 throws ClassNotFoundException when trying to integrate database access

无人久伴 提交于 2019-12-31 05:17:07
问题 I have a simple SpringBoot 2.1.0 application and try to add the database-connectivity with JPA . Everything is set up with the " spring-boot-starter-data-jpa " dependency in pom.xml , but when I start the application, I get this ClassNotFoundException . I tried already adding byte-buddy manually as dependency, but this changes nothing. Has someone solved this problem already? Many thanks for every hint in advance! org.springframework.beans.factory.BeanCreationException: Error creating bean

How can I generate method with byte buddy?

久未见 提交于 2019-12-25 02:57:15
问题 This is a followup question of How can I get Annotation class from TypeDescription I'm trying to generate methods using Plugin . With given class such as. class { @Func T some; } I located the field with specific annotation. And I'm asking for help to create a method look like this. public <R> R applySome(Function<T, R> function) { return function.apply(some); } How can I make the method in @Override public DynamicType.Builder<?> apply(final DynamicType.Builder<?> builder, final

How to attach bytebuddy agent when target application load classes from uRLConnection.getInputStream

。_饼干妹妹 提交于 2019-12-25 00:17:28
问题 I made a java agent with bytebuddy. It works well untill target application load classes form uRLConnection.getInputStream. The target app works well without attachment the agent, but shows exception [java.lang.ClassNotFoundException] when the agent attached. this is app's classloading line. return this.getClass().getClassLoader().loadClass(string) //string points the name of a byte array. In the application, the classes is provided in the form of byte array from the uRLConnection

ByteBuddy rebasing, synthetic types and OSGi

爱⌒轻易说出口 提交于 2019-12-24 15:04:21
问题 I have the following interceptor developed for byte-buddy: public class SecurityInterceptor() { @RuntimeType public static Object intercept( @SuperCall Callable<Object> supercall, @This Object target, @Origin Method method, @AllArguments Object[] args) { // Check args and annotations ... Object obj = supercall.call(); // Post-process obj content ... } } The interceptor is registered as follows: Unloaded<Object> unloaded = new ByteBuddy() .rebase(type, classFileLocator) .method(ElementMatchers

Add method annotation at runtime with Byte Buddy

孤者浪人 提交于 2019-12-24 05:12:44
问题 I've been searching for the answer to "how to add an annotation to the method at runtime" for several days already and found this awesome tool called Byte Buddy, played with it, but still cannot make it work as I need to. I'm sure it must be able to do that from this question Can Byte Buddy create fields and method annotations at runtime? Having this class: public class ClassThatNeedsToBeAnnotated { public void method(int arg1, String arg2) { // code that we don't want to touch at all, leave

Add method annotation at runtime with Byte Buddy

六眼飞鱼酱① 提交于 2019-12-24 05:12:27
问题 I've been searching for the answer to "how to add an annotation to the method at runtime" for several days already and found this awesome tool called Byte Buddy, played with it, but still cannot make it work as I need to. I'm sure it must be able to do that from this question Can Byte Buddy create fields and method annotations at runtime? Having this class: public class ClassThatNeedsToBeAnnotated { public void method(int arg1, String arg2) { // code that we don't want to touch at all, leave

Why doesn't ASM call my ``visitCode``?

混江龙づ霸主 提交于 2019-12-24 00:58:54
问题 I'll add my code to the end of this post. I'm using byteBuddy 1.7.9 and whatever ASM version comes with that. In a nutshell I have byte[] rawClass = ...; ClassReader cr = new ClassReader(rawClass); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); MethodAdder ma = new MethodAdder(Opcodes.ASM5,cw); cr.accept(ma,ClassReader.EXPAND_FRAMES); Where in MethodAdder , I want to add a static initialiser: @Override public MethodVisitor visitMethod(int access, String name, String desc,

Can Byte Buddy create fields and method annotations at runtime?

房东的猫 提交于 2019-12-23 03:51:37
问题 I would like to implement this 3rd-party annotation to map my class's fields/properties to my database table columns. I can easily implement the annotations at compile time (as shown in the example code below) but I can't find a way to do this at runtime. (I am loading the library at runtime using reflection.) My question is how can I implement the same mapping annotation when loading a library at run time? Can Byte Buddy handle this for Android? //3rd party annotation code package weborb