2

I want to ignore the instrumentation for methods which are abstract to source class and target object but if it is abstract method for source alone then i would like to call the equivalent method on target object. Currently i am using this

adapter = new ByteBuddy().subclass(source.class)
.method(ElementMatchers.isAbstract())
.intercept(MethodCall.invokeSelf().on(target).withAllArguments()).make()
                            .load(clazz.getClassLoader(),ClassLoadingStrategy.Default.INJECTION).getLoaded().newInstance()

but getting these kind of exceptions The abstract methods which does not have implementation neither in source class nor in target object is failing with below error.

Cannot invoke public abstract java.lang.Object java.sql.Wrapper.unwrap(java.lang.Class) throws java.sql.SQLException on public static volatile java.lang.Class com.demo.Source$ByteBuddy$f7N2VK0l.invocationTarget$fl948k0

Can I achieve any one of the below scenario if the method is abstract in both cases?

  1. Ignore instrumentation for abstract methods which does not have implementation in both source and target.
  2. Redirect unmatched method to a default method.

1 Answers1

0

If you know the exact target type, you could determine this in the matcher? Implement your own matcher in such a case.

You could also use MethodDelegation and the Pipe annotation. Here, you could catch an exception and return a fallback.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192