Hi Denis,
I will try to write a test case for this problem, could please exactly describe what to do (pseudo code) to reproduce this bug.
regards, Armin
[EMAIL PROTECTED] wrote:
Hi all,
I've just upgraded to RC7, and I'm now getting the following error on a call to PersistenceBroker.retrieveAllReferences():
java.lang.NullPointerException
at org.apache.ojb.broker.util.BrokerHelper.representsNull(BrokerHelper.java:260)
at org.apache.ojb.broker.core.QueryReferenceBroker.hasNullifiedFK(QueryReferenceBroker.java:446)
at org.apache.ojb.broker.core.QueryReferenceBroker.getReferencedObjectIdentity(QueryReferenceBroker.java:410)
at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReference(QueryReferenceBroker.java:334)
at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReferences(QueryReferenceBroker.java:396)
at org.apache.ojb.broker.core.PersistenceBrokerImpl.retrieveAllReferences(PersistenceBrokerImpl.java:1145)
at ...
It seems that the problem is in the BrokerHelper.representsNull method. The field it is complaining about is "reportNumber", which is an anonymous field in the target class. Here's my class descriptor:
<class-descriptor
class="ca.richer.domain.OutOfService"
table="FDJ8CPP"
... other fields omitted for brevity ... <field-descriptor name="reportNumber" column="J8RZNB" jdbc-type="DECIMAL" precision="20" scale="0" access="anonymous" > </field-descriptor> <field-descriptor name="lineSequence" column="J8R0NB" jdbc-type="DECIMAL" precision="20" scale="0" access="anonymous" > </field-descriptor> <reference-descriptor name="defectLine" class-ref="ca.richer.domain.DefectLine" > <foreignkey field-ref="reportNumber"/> <foreignkey field-ref="lineSequence"/> </reference-descriptor> </class-descriptor>
The problem is that AnonymousPersistentField.getType() always returns null, so a NullPointerException is thrown when the BrokerHelper tries to determine if this field represents a primitive type.
I would suggest the following patch: public boolean representsNull(FieldDescriptor fld, Object aValue) { if(aValue == null) return true;
boolean result = false;
if(((aValue instanceof Number) && (((Number) aValue).longValue() == 0)))
{
// PATCH STARTS HERE
PersistentField field = fld.getPersistentField();
Class type = field.getType();
// AnonymousPersistentFields will *always* have a null type according to the
// javadoc comments in AnonymousPersistentField.getType()
if (type == null) {
return true;
}
result = type.isPrimitive();
// PATCH ENDS HERE
}
else if((aValue instanceof String) && (((String) aValue).length() == 0))
{
result = fld.isPrimaryKey();
}
return result;
}
Maybe I've overlooked something, but if this method is ever called with an anonymous field with a value of 0, it will surely throw a NPE. Thoughts?
Thanks, Phil Denis
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
