<reference-descriptor
name="legalName"
class-ref="test.BasicLegalName"
proxy="true"
>
<foreignkey field-ref="id"/>
<foreignkey field-ref="type"/>
</reference-descriptor>If the reference exists, everything works perfectly: I can dereference like this
person.getLegalName().getFirstName()
However, if the reference does not exist, the above dereference throws a PersistenceBrokerException wrapping a NullPointerException with the following error message:
Method invoking failed for method *getFirstName* on object null
The stack trace starts off with
java.lang.NullPointerException
at org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown Source)
at $Proxy25.getFirstName(Unknown Source)
Tracking this down to the invoke() method, there is no check as to whether the reference actually exists; the code just calls the method on the materialized subject:
subject = getRealSubject();
return method.invoke(subject, args);
My questions are:
1) Should this method be changed to return a default value based on the return type of the method being invoked, in the case where subject is null (e.g., null for an object, 0 for an int, false for a boolean, etc.)? Or at the very least, return null in all cases if subject is null?
2) How can I check whether a proxy reference is null? Is there a way to do this transparently?
I've read other messages in the archive about this issue, but I haven't really seen a solution to it. The solution proposed here didn't seem to do anything for me: http://www.mail-archive.com/[EMAIL PROTECTED]/msg00132.html
How are other people handling this?
Thanks Andrew
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
