Hi Edson,

it's strange. I can find two places in code using getCollectionIterator(...), but can't figure out where the NPE was could be thrown.
In PB.deleteCollections(...) a 'null' check is done (line 623).
In PB.storeCollections(...) it is possible that null could be passed (line 862), but if we return null in getCollectionIterator will end up with a NPE.
Maybe I'm overlooked something. Could shed light on this?


regards,
Armin

Edson Carlos Ericksson Richter wrote:

Yes, works fine if modifying the method to:

    private Iterator getCollectionIterator(CollectionDescriptor cds, Object
collectionOrArray)
    {
        Iterator colIterator;

        if(collectionOrArray == null) {
          return null;
        }

        if (collectionOrArray instanceof ManageableCollection)
        {
            colIterator = ((ManageableCollection)
collectionOrArray).ojbIterator();
        }
        else if (collectionOrArray instanceof Collection)
        {
            colIterator = ((Collection) collectionOrArray).iterator();
        }
        else if (collectionOrArray.getClass().isArray())
        {
            colIterator = new ArrayIterator(collectionOrArray);
        }
        else
        {
            String fieldName =
cds.getClassDescriptor().getClassNameOfObject() + "." +
cds.getAttributeName();
            throw new OJBRuntimeException(
                "Field '"
                    + fieldName
                    + "' "
                    + collectionOrArray.getClass()
                    + " can not be managed by OJB. Use Array, Collection or
ManageableCollection instead !");
        }
        return colIterator;
    }


----- Original Message ----- From: Edson Carlos Ericksson Richter
To: 'OJB Users List'
Sent: Tuesday, March 23, 2004 3:36 PM
Subject: Problem in PersistenceBrokerImpl



Hi!


I've found a little bug in PersistenceBrokerImpl (latest CVS - downloaded 10
min ago), that can cause a NPE when storing:

    private Iterator getCollectionIterator(CollectionDescriptor cds, Object
collectionOrArray)
    {
        Iterator colIterator;

        if (collectionOrArray instanceof ManageableCollection)
        {
            colIterator = ((ManageableCollection)
collectionOrArray).ojbIterator();
        }
        else if (collectionOrArray instanceof Collection)
        {
            colIterator = ((Collection) collectionOrArray).iterator();
        }
        else if (collectionOrArray.getClass().isArray())
        {
            colIterator = new ArrayIterator(collectionOrArray);
        }
        else
        {
            String fieldName =
cds.getClassDescriptor().getClassNameOfObject() + "." +
cds.getAttributeName();
            throw new OJBRuntimeException(
                "Field '"
                    + fieldName
                    + "' "
                    + collectionOrArray.getClass()
                    + " can not be managed by OJB. Use Array, Collection or
ManageableCollection instead !");
        }
        return colIterator;
    }


The problem occur when collectionOrArray is null. I'm trying to put a test like:

if(collectionOrArray==null) {
  return null;
}

as solution. I'll let you know if this solves.

Thanks,

Edson Richter





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.637 / Virus Database: 408 - Release Date: 20/3/2004

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to