You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/11/19 06:33:03 UTC
[GitHub] honganan commented on issue #1935: Executing order of constructor
interception issue
honganan commented on issue #1935: Executing order of constructor interception issue
URL: https://github.com/apache/incubator-skywalking/issues/1935#issuecomment-439785733
It works, If you don't use `@This` or `@SuperCall` in the interceptor.
I have a test like this, and this could run correctly:
```java
public class ConstructInstrumentation1 {
public static void main(String[] args) {
TypePool typePool = TypePool.Default.ofClassPath();
new ByteBuddy()
.rebase(typePool.describe("cn.iocoder.learning.bytebuddy.Dog").resolve(), // do not use 'Bar.class'
ClassFileLocator.ForClassLoader.ofClassPath())
.constructor(takesArgument(0, String.class))
.intercept(to(MyConstructInterceptor.class).andThen(SuperMethodCall.INSTANCE)) // This makes the difference!
.make()
.load(ConstructInstrumentation1.class.getClassLoader(), INJECTION);
new Dog("huang").hello();
}
}
public class MyConstructInterceptor {
@RuntimeType
public static void intercept(@AllArguments Object[] allArguments) throws Exception {
System.out.println("interceptor");
}
}
public class Dog {
private String name;
public Dog(String name) {
this.name = name;
System.out.println("constructor");
}
public void hello() {}
}
```
and the output is:
```java
interceptor
constructor
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services