You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br> on 2004/03/23 19:36:08 UTC

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

Re: Problem in PersistenceBrokerImpl

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
Ops, I'm sorry. I think I'm overcharged :-( ... The problem occur when
storing.
I have no stack trace at all to send to you in this moment.

When I recompile OJB, I'll send it to you (if it occur).

Thanks by your attention.

Edson Richter



----- Original Message ----- 
From: Armin Waibel
To: OJB Users List
Sent: Wednesday, March 24, 2004 9:36 AM
Subject: Re: Problem in PersistenceBrokerImpl


Edson Carlos Ericksson Richter wrote:

> I had not so much time to investigate: I fixed because I need to upgrade
> to 1.0.0 ASAP (due to other fixes).
>

ok, no problem. Could you send me the stack trace?

> I'll double check the stack trace because the problems is occurring when
> querying, not storing neither deleting.
>

hmm querying, that's strange again. The query methods never use
getCollectionIterator method.

regards,
Armin

> Best regards,
>
> Edson Richter
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


---
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem in PersistenceBrokerImpl

Posted by Armin Waibel <ar...@apache.org>.
Edson Carlos Ericksson Richter wrote:

> I had not so much time to investigate: I fixed because I need to upgrade
> to 1.0.0 ASAP (due to other fixes).
>

ok, no problem. Could you send me the stack trace?

> I'll double check the stack trace because the problems is occurring when
> querying, not storing neither deleting.
> 

hmm querying, that's strange again. The query methods never use 
getCollectionIterator method.

regards,
Armin

> Best regards,
> 
> Edson Richter
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem in PersistenceBrokerImpl

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
I had not so much time to investigate: I fixed because I need to upgrade
to 1.0.0 ASAP (due to other fixes).

I'll double check the stack trace because the problems is occurring when
querying, not storing neither deleting.

Best regards,

Edson Richter



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem in PersistenceBrokerImpl

Posted by Armin Waibel <ar...@apache.org>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem in PersistenceBrokerImpl

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
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