I have seen that when errors occur deep in different frameworks (e.g frameworks implementing the EJB specification or some JPA providers) the stacktrace contain classes like
Proxies are classes that are created and loaded at runtime. There is no source code for these classes. I know that you are wondering how you can make them do something if there is no code for them. The answer is that when you create them, you specify an object that implements
InvocationHandler, which defines a method that is invoked when a proxy method is invoked.
You create them by using the call
Proxy.newProxyInstance(classLoader, interfaces, invocationHandler)
The arguments are:
classLoader. Once the class is generated, it is loaded with this class loader.
interfaces. An array of class objects that must all be interfaces. The resulting proxy implements all of these interfaces.
invocationHandler. This is how your proxy knows what to do when a method is invoked. It is an object that implements
InvocationHandler. When a method from any of the supported interfaces, or
toString, is invoked, the method
invokeis invoked on the handler, passing the
Methodobject for the method to be invoked and the arguments passed.
For more on this, see the documentation for the
Every implementation of a JVM after version 1.3 must support these. They are loaded into the internal data structures of the JVM in an implementation-specific way, but it is guaranteed to work.