Like i have mentioned in the email, from PojoCache side, I am not trying to serialize anInstanceOfTheProxy. Instead, I am trying to serializing the Class definition itself (so I can reconstruct the new instance from there). E.g., in terms of cache operation,
put(fqn, key, anInstanceOfAopPoxy.getClass())
Of course, we can argue that I may be able to get around this by simply passing the class name *String*. But that is a different story, IMO.
I know you are not serializing an instance of the proxy, and that's my whole point.
How can you reconstruct the proxy by its class reference only?
When you serialize that, you are serializing a name, and you will be trusting on the classLoader to give you the correct reference back.
When you ask the classLoader the Proxy by its name, you can get a proxied class on a different class.
You should improve your logic somehow, in such way you never do this:
The JDK don't know how to handle AOPProxies.
I don't know how you are going to fix this. I just know this is an invalid (semanticaly) operation, and I wanted to let you know that.
If you want to discuss options, this is what I think:
I - Serialize an instance of the proxy, since the instance can serialize itself correctly.
II - Put the proxy definition in a wrapper class that will know how to recreate the proxy.
III - Send proxy.getSuperClass() instead, and recreate the proxy from there.
Well.. I don't konw much about POJOCache, so I don't know what's the best approach for you.
put(fqn, key, anInstanceOfAopPoxy.getClass()) ;
can lead you in an error.
You just need to have one of the JVMs creating an AOP proxy before the other. specially now Hibernate is also using AOPProxies, this is not so difficult to happen.
If you still think I'm wrong, let me translate to you what will happen on java.io.ObjectOUtputStream and INputSTream:
This is the same thing as:
Class proxyClass = (Class)objectInputStream.readObject()
This is the same thing as:
String className = input.readUTF();
Class proxyClass = theClassLoader.loadClass(className);
So, this is why I'm picking up on the fact you are trusting the classLoader to give you the correct proxy reference.
Just to complete my point:
if you were saving java.lang.Proxy.getClass(), the history would be completely different.
This is because the JDK (ObjectOUtputSTream) has a special persister:
//// save the interfaces for later reconstructions
ont the read.
Class  interfaces = readTheInterfaces.
The JDK don't know how to save AOPPRoxy classes.
Got it. Since I am only sending the Class object to the remote node (for it to reconstruct the no-arg isntance), I can do like your suggestion of proxy.getSuperClass() instead.
Thanks a lot!
Could this serialisation be part of the EnhancedTreeCacheMarshaller? We're already improving the way the MethodCalls and other objects are serialised using EnhancedTreeCacheMarshaller.
No, it should not since it is PojoCache specific. I have resolved this issue.