1

I am working on dynamic proxy creation on concrete classes. Since java's plain Proxy class does help only with Interfaces , I chose CGLIb.
I am using Enhancer class with MethodInterceptor for intercepting the methods of my proxy and I am able to intercept all method calls but static methods.

Is there any way to intercept calls to static methods using CGLIb?

Suresh Anbarasan
  • 943
  • 1
  • 8
  • 20

1 Answers1

1

This is not possible, cglib instruments classes by creating a subclass where all methods are overriden to apply the interception logic. This is not possible for static methods such that cglib does not support this.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • Thank you! Is there any other way to accomplish static instrumentation without modifying the method library. My understanding is that, Through Java assist we can rewrite the method with new definition. But I do not want to do use javaassist. – Suresh Anbarasan Jun 21 '16 at 16:07
  • You can have a look at Javassist and Byte Buddy. Both allow class redefinition to do so. – Rafael Winterhalter Jun 21 '16 at 21:22