Using aspects to inject InvocationHandlers without Proxy class

184 views Asked by At

I want to create a class which proxies all calls to methods to its superclass with log information (i.e. before/after statements, for example).

However, the framework using this class will be loading it via the new (..) invocation, or else, via other reflection mechanisms, so I can't use the Proxy semantics to launch the class.

Is there a way to get the new and newInstance() operations to use a Proxy in all cases - or do we have to explictly create instances of a InvocationHandler class using the Proxy API?

Specifically: I'm debugging a distributed framework which already has its own way of creating class instances from XML files at runtime (hadoop - mapreduce).

1

There are 1 answers

2
Enno Shioji On

I don't think you can monkey patch in Java easily. I think you could try AOP, or hacking the class directly (as you'll have the source since it's hadoop). Otherwise I think reflection or byte code modification could be an option, but they are all going to be very nasty. Hacking the class directly and using a hacked jar sounds like the most straightforward way to me.

Btw Hi :)