Hibernate version:
3.0b3
I've got a lazy object with a method that does "return this;" because that specific instance implement also other interfaces.
When I try to invoke that method I always get a ClassCastException.
Debugging the code I've found this:
CGLIBLazyInitializer
Code:
public Object intercept(
final Object obj,
final Method method,
final Object[] args,
final MethodProxy proxy)
throws Throwable {
if (constructed) {
Object result = invoke(method, args, obj);
if (result==INVOKE_IMPLEMENTATION) {
Object target = getImplementation();
Object retval = proxy.invoke(target, args);
>>> return (retval==target) ? this : retval; <<<
}
else {
return result;
}
}
else {
//while constructor is running
return proxy.invokeSuper(obj, args);
}
}
Well, if the method invoked on target returns target (my use case) then this method return
this (
the CGLIBLazyInitializer) instead of method return value...
I think it should return "
obj" instead of "
this"!
Am I right?