You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Teresa Kan (JIRA)" <ji...@apache.org> on 2007/06/20 00:03:25 UTC

[jira] Created: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

NullPointerException occurred in BrokerImpl.java
------------------------------------------------

                 Key: OPENJPA-261
                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 0.9.7
         Environment: Window XP
            Reporter: Teresa Kan
            Priority: Critical


While I was testing against the openjpa code, I got a NPE in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code did not check this Collection and tried to iterate on it and a NullPointerException occurred.

Original code:

Collection transStates = _transCache;
        if (transStates == null)
            transStates = Collections.EMPTY_LIST;
.....
for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }

I put a check before this "for" loop then the NPE disappeared.

if (!transStates.isEmpty()) {   
        	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }
        }
The NPE.patch is attached in this jiar. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by Teresa Kan <tc...@gmail.com>.
Craig,
Thanks for updating the description. There is still one NPE here.

"I put a check before this "for" loop then the NPE disappeared.". Please
change it to
"I put a check before this "for" loop then the UnsupportedOperationException
disappeared."
Or it doesn't matter..

Thanks again
Teresa




On 6/19/07, Craig L Russell <Cr...@sun.com> wrote:
>
> Hi Teresa,
>
> I've edited the JIRA but you should look and see if it makes sense
> with the minimum editing I did.
>
> Craig
>
> On Jun 19, 2007, at 4:08 PM, Teresa Kan wrote:
>
> > Is there a way to change the JIAR subject to
> > UnsupportedOperationException?
> >
> >
> >
> > On 6/19/07, Teresa Kan < tckan1@gmail.com> wrote:
> >>
> >> Sorry it was not NPE, it was UnsupportedOperationException. I had
> >> the NPE
> >> before and somehow mixed up with two. Anyway, it caused by :
> >> java.lang.UnsupportedOperationException: IteratorChains must
> >> contain at
> >> least one Iterator
> >>
> >> The Collecitons.EMPTY_LIST.iterator() does not return null.
> >> Here is the exception stack:
> >>
> >> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred
> >> while
> >> ending the transaction. This exception will be re-thrown.
> >>
> >> <0.0.0 nonfatal user error>
> >> org.apache.openjpa.util.NoTransactionException:
> >> Can only perform operation while a transaction is active.
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(
> >> BrokerImpl.java:4307)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion
> >> (BrokerImpl.java
> >> :1806)
> >>
> >> at org.apache.openjpa.kernel.LocalManagedRuntime.rollback (
> >> LocalManagedRuntime.java:123)
> >>
> >> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> >> LocalManagedRuntime.java:104)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.commit (BrokerImpl.java:1319)
> >>
> >> at org.apache.openjpa.kernel.DelegatingBroker.commit
> >> (DelegatingBroker.java
> >> :869)
> >>
> >> at org.apache.openjpa.persistence.EntityManagerImpl.commit (
> >> EntityManagerImpl.java:409)
> >>
> >> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
> >>
> >> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred
> >> while
> >> ending the transaction. This exception will be re-thrown.
> >>
> >> <0.0.0 nonfatal store error> org.apache.openjpa.util.StoreException:
> >> IteratorChains must contain at least one Iterator
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion
> >> (BrokerImpl.java
> >> :1833)
> >>
> >> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> >> LocalManagedRuntime.java:93)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
> >>
> >> at org.apache.openjpa.kernel.DelegatingBroker.commit
> >> (DelegatingBroker.java
> >> :869)
> >>
> >> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> >> EntityManagerImpl.java:409)
> >>
> >> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java :135)
> >>
> >> Caused by: java.lang.UnsupportedOperationException: IteratorChains
> >> must
> >> contain at least one Iterator
> >>
> >> at
> >> org.apache.commons.collections.iterators.IteratorChain.checkChainInte
> >> grity(Unknown
> >> Source)
> >>
> >> at org.apache.commons.collections.iterators.IteratorChain.lockChain
> >> (Unknown
> >> Source)
> >>
> >> at org.apache.commons.collections.iterators.IteratorChain.hasNext
> >> (Unknown
> >> Source)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.endTransaction
> >> (BrokerImpl.java
> >> :2196)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion
> >> (BrokerImpl.java
> >> :1809)
> >>
> >> ... 5 more
> >>
> >> <0.0.0 fatal store error>
> >> org.apache.openjpa.persistence.RollbackException:
> >> IteratorChains must contain at least one Iterator
> >>
> >> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> >> EntityManagerImpl.java:420)
> >>
> >> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
> >>
> >> Caused by: <0.0.0 nonfatal general error>
> >> org.apache.openjpa.persistence.PersistenceException:
> >> IteratorChains must
> >> contain at least one Iterator
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion
> >> (BrokerImpl.java
> >> :1833)
> >>
> >> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> >> LocalManagedRuntime.java:93)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
> >>
> >> at org.apache.openjpa.kernel.DelegatingBroker.commit
> >> (DelegatingBroker.java
> >> :869)
> >>
> >> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> >> EntityManagerImpl.java:409)
> >>
> >> ... 1 more
> >>
> >> Caused by: java.lang.UnsupportedOperationException : IteratorChains
> >> must
> >> contain at least one Iterator
> >>
> >> at
> >> org.apache.commons.collections.iterators.IteratorChain.checkChainInte
> >> grity(Unknown
> >> Source)
> >>
> >> at org.apache.commons.collections.iterators.IteratorChain.lockChain
> >> (Unknown
> >> Source)
> >>
> >> at org.apache.commons.collections.iterators.IteratorChain.hasNext
> >> (Unknown
> >> Source)update different fields
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.endTransaction
> >> (BrokerImpl.java
> >> :2196)
> >>
> >> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion
> >> (BrokerImpl.java
> >> :1809)
> >>
> >> ... 5 more
> >>
> >>
> >> On 6/19/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
> >> >
> >> >
> >> >    [
> >> > https://issues.apache.org/jira/browse/OPENJPA-261?
> >> page=com.atlassian.jira.plugin.system.issuetabpanels:comment-
> >> tabpanel#action_12506312]
> >> >
> >> > Patrick Linskey commented on OPENJPA-261:
> >> > -----------------------------------------
> >> >
> >> > So you're saying that Collections.EMPTY_LIST.iterator() is
> >> returning
> >> > null? That seems surprising. What version of Java are you using?
> >> Can you
> >> > check if your Java version is returning null from
> >> > Collecitons.EMPTY_LIST.iterator ()?
> >> >
> >> > > NullPointerException occurred in BrokerImpl.java
> >> > > ------------------------------------------------
> >> > >
> >> > >                 Key: OPENJPA-261
> >> > >                 URL: https://issues.apache.org/jira/browse/
> >> OPENJPA-261
> >> > >             Project: OpenJPA
> >> > >          Issue Type: Bug
> >> > >          Components: kernel
> >> > >    Affects Versions: 0.9.7
> >> > >         Environment: Window XP
> >> > >            Reporter: Teresa Kan
> >> > >            Priority: Critical
> >> > >         Attachments: NPE.patch
> >> > >
> >> > >
> >> > > While I was testing against the openjpa code, I got a NPE in the
> >> > BrokerImpl.endtransaction () method. The method set the
> >> transState to an
> >> > empty Collection if there is no cache for transactions. Later
> >> the code did
> >> > not check this Collection and tried to iterate on it and a
> >> > NullPointerException occurred.
> >> > > Original code:
> >> > > Collection transStates = _transCache;
> >> > >         if (transStates == null)
> >> > >             transStates = Collections.EMPTY_LIST;
> >> > > .....
> >> > > for (Iterator itr = transStates.iterator(); itr.hasNext ();)
> >> {  <---
> >> > NPE occurred here.
> >> > >             sm = (StateManagerImpl) itr.next();
> >> > >             try {
> >> > >                 if (rollback) {
> >> > >                     // tell objects that may have been derefed
> >> then
> >> > flushed
> >> > >                     // (and therefore deleted) to un-deref
> >> > >                     sm.setDereferencedDependent(false, false);
> >> > >                     sm.rollback();
> >> > >                 } else
> >> > >                     sm.commit();
> >> > >             } catch (RuntimeException re) {
> >> > >                 exceps = add(exceps, re);
> >> > >             }
> >> > >          }
> >> > > I put a check before this "for" loop then the NPE disappeared.
> >> > > if (!transStates.isEmpty()) {
> >> > >               for (Iterator itr = transStates.iterator();
> >> itr.hasNext();)
> >> > {
> >> > >             sm = (StateManagerImpl) itr.next();
> >> > >             try {
> >> > >                 if (rollback) {
> >> > >                     // tell objects that may have been derefed
> >> then
> >> > flushed
> >> > >                     // (and therefore deleted) to un-deref
> >> > >                     sm.setDereferencedDependent(false, false);
> >> > >                     sm.rollback();
> >> > >                 } else
> >> > >                     sm.commit();
> >> > >             } catch (RuntimeException re) {
> >> > >                 exceps = add(exceps, re);
> >> > >             }
> >> > >          }
> >> > >         }
> >> > > The NPE.patch is attached in this jiar.
> >> >
> >> > --
> >> > This message is automatically generated by JIRA.
> >> > -
> >> > You can reply to this email to add a comment to the issue online.
> >> >
> >> >
> >>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto: Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>

Re: [jira] Commented: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Teresa,

I've edited the JIRA but you should look and see if it makes sense  
with the minimum editing I did.

Craig

On Jun 19, 2007, at 4:08 PM, Teresa Kan wrote:

> Is there a way to change the JIAR subject to  
> UnsupportedOperationException?
>
>
>
> On 6/19/07, Teresa Kan <tc...@gmail.com> wrote:
>>
>> Sorry it was not NPE, it was UnsupportedOperationException. I had  
>> the NPE
>> before and somehow mixed up with two. Anyway, it caused by :
>> java.lang.UnsupportedOperationException: IteratorChains must  
>> contain at
>> least one Iterator
>>
>> The Collecitons.EMPTY_LIST.iterator() does not return null.
>> Here is the exception stack:
>>
>> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred  
>> while
>> ending the transaction. This exception will be re-thrown.
>>
>> <0.0.0 nonfatal user error>  
>> org.apache.openjpa.util.NoTransactionException:
>> Can only perform operation while a transaction is active.
>>
>> at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(
>> BrokerImpl.java:4307)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion 
>> (BrokerImpl.java
>> :1806)
>>
>> at org.apache.openjpa.kernel.LocalManagedRuntime.rollback(
>> LocalManagedRuntime.java:123)
>>
>> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
>> LocalManagedRuntime.java:104)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>>
>> at org.apache.openjpa.kernel.DelegatingBroker.commit 
>> (DelegatingBroker.java
>> :869)
>>
>> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
>> EntityManagerImpl.java:409)
>>
>> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>>
>> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred  
>> while
>> ending the transaction. This exception will be re-thrown.
>>
>> <0.0.0 nonfatal store error> org.apache.openjpa.util.StoreException:
>> IteratorChains must contain at least one Iterator
>>
>> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion 
>> (BrokerImpl.java
>> :1833)
>>
>> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
>> LocalManagedRuntime.java:93)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>>
>> at org.apache.openjpa.kernel.DelegatingBroker.commit 
>> (DelegatingBroker.java
>> :869)
>>
>> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
>> EntityManagerImpl.java:409)
>>
>> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>>
>> Caused by: java.lang.UnsupportedOperationException: IteratorChains  
>> must
>> contain at least one Iterator
>>
>> at
>> org.apache.commons.collections.iterators.IteratorChain.checkChainInte 
>> grity(Unknown
>> Source)
>>
>> at org.apache.commons.collections.iterators.IteratorChain.lockChain 
>> (Unknown
>> Source)
>>
>> at org.apache.commons.collections.iterators.IteratorChain.hasNext 
>> (Unknown
>> Source)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.endTransaction 
>> (BrokerImpl.java
>> :2196)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion 
>> (BrokerImpl.java
>> :1809)
>>
>> ... 5 more
>>
>> <0.0.0 fatal store error>  
>> org.apache.openjpa.persistence.RollbackException:
>> IteratorChains must contain at least one Iterator
>>
>> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
>> EntityManagerImpl.java:420)
>>
>> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>>
>> Caused by: <0.0.0 nonfatal general error>
>> org.apache.openjpa.persistence.PersistenceException:  
>> IteratorChains must
>> contain at least one Iterator
>>
>> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion 
>> (BrokerImpl.java
>> :1833)
>>
>> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
>> LocalManagedRuntime.java:93)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>>
>> at org.apache.openjpa.kernel.DelegatingBroker.commit 
>> (DelegatingBroker.java
>> :869)
>>
>> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
>> EntityManagerImpl.java:409)
>>
>> ... 1 more
>>
>> Caused by: java.lang.UnsupportedOperationException: IteratorChains  
>> must
>> contain at least one Iterator
>>
>> at
>> org.apache.commons.collections.iterators.IteratorChain.checkChainInte 
>> grity(Unknown
>> Source)
>>
>> at org.apache.commons.collections.iterators.IteratorChain.lockChain 
>> (Unknown
>> Source)
>>
>> at org.apache.commons.collections.iterators.IteratorChain.hasNext 
>> (Unknown
>> Source)update different fields
>>
>> at org.apache.openjpa.kernel.BrokerImpl.endTransaction 
>> (BrokerImpl.java
>> :2196)
>>
>> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion 
>> (BrokerImpl.java
>> :1809)
>>
>> ... 5 more
>>
>>
>> On 6/19/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
>> >
>> >
>> >    [
>> > https://issues.apache.org/jira/browse/OPENJPA-261? 
>> page=com.atlassian.jira.plugin.system.issuetabpanels:comment- 
>> tabpanel#action_12506312]
>> >
>> > Patrick Linskey commented on OPENJPA-261:
>> > -----------------------------------------
>> >
>> > So you're saying that Collections.EMPTY_LIST.iterator() is  
>> returning
>> > null? That seems surprising. What version of Java are you using?  
>> Can you
>> > check if your Java version is returning null from
>> > Collecitons.EMPTY_LIST.iterator ()?
>> >
>> > > NullPointerException occurred in BrokerImpl.java
>> > > ------------------------------------------------
>> > >
>> > >                 Key: OPENJPA-261
>> > >                 URL: https://issues.apache.org/jira/browse/ 
>> OPENJPA-261
>> > >             Project: OpenJPA
>> > >          Issue Type: Bug
>> > >          Components: kernel
>> > >    Affects Versions: 0.9.7
>> > >         Environment: Window XP
>> > >            Reporter: Teresa Kan
>> > >            Priority: Critical
>> > >         Attachments: NPE.patch
>> > >
>> > >
>> > > While I was testing against the openjpa code, I got a NPE in the
>> > BrokerImpl.endtransaction () method. The method set the  
>> transState to an
>> > empty Collection if there is no cache for transactions. Later  
>> the code did
>> > not check this Collection and tried to iterate on it and a
>> > NullPointerException occurred.
>> > > Original code:
>> > > Collection transStates = _transCache;
>> > >         if (transStates == null)
>> > >             transStates = Collections.EMPTY_LIST;
>> > > .....
>> > > for (Iterator itr = transStates.iterator(); itr.hasNext ();)  
>> {  <---
>> > NPE occurred here.
>> > >             sm = (StateManagerImpl) itr.next();
>> > >             try {
>> > >                 if (rollback) {
>> > >                     // tell objects that may have been derefed  
>> then
>> > flushed
>> > >                     // (and therefore deleted) to un-deref
>> > >                     sm.setDereferencedDependent(false, false);
>> > >                     sm.rollback();
>> > >                 } else
>> > >                     sm.commit();
>> > >             } catch (RuntimeException re) {
>> > >                 exceps = add(exceps, re);
>> > >             }
>> > >          }
>> > > I put a check before this "for" loop then the NPE disappeared.
>> > > if (!transStates.isEmpty()) {
>> > >               for (Iterator itr = transStates.iterator();  
>> itr.hasNext();)
>> > {
>> > >             sm = (StateManagerImpl) itr.next();
>> > >             try {
>> > >                 if (rollback) {
>> > >                     // tell objects that may have been derefed  
>> then
>> > flushed
>> > >                     // (and therefore deleted) to un-deref
>> > >                     sm.setDereferencedDependent(false, false);
>> > >                     sm.rollback();
>> > >                 } else
>> > >                     sm.commit();
>> > >             } catch (RuntimeException re) {
>> > >                 exceps = add(exceps, re);
>> > >             }
>> > >          }
>> > >         }
>> > > The NPE.patch is attached in this jiar.
>> >
>> > --
>> > This message is automatically generated by JIRA.
>> > -
>> > You can reply to this email to add a comment to the issue online.
>> >
>> >
>>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: [jira] Commented: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by Teresa Kan <tc...@gmail.com>.
Is there a way to change the JIAR subject to UnsupportedOperationException?



On 6/19/07, Teresa Kan <tc...@gmail.com> wrote:
>
> Sorry it was not NPE, it was UnsupportedOperationException. I had the NPE
> before and somehow mixed up with two. Anyway, it caused by :
> java.lang.UnsupportedOperationException: IteratorChains must contain at
> least one Iterator
>
> The Collecitons.EMPTY_LIST.iterator() does not return null.
> Here is the exception stack:
>
> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
> ending the transaction. This exception will be re-thrown.
>
> <0.0.0 nonfatal user error> org.apache.openjpa.util.NoTransactionException:
> Can only perform operation while a transaction is active.
>
> at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(
> BrokerImpl.java:4307)
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
> :1806)
>
> at org.apache.openjpa.kernel.LocalManagedRuntime.rollback(
> LocalManagedRuntime.java:123)
>
> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> LocalManagedRuntime.java:104)
>
> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>
> at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
> :869)
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> EntityManagerImpl.java:409)
>
> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>
> 4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
> ending the transaction. This exception will be re-thrown.
>
> <0.0.0 nonfatal store error> org.apache.openjpa.util.StoreException:
> IteratorChains must contain at least one Iterator
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
> :1833)
>
> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> LocalManagedRuntime.java:93)
>
> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>
> at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
> :869)
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> EntityManagerImpl.java:409)
>
> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>
> Caused by: java.lang.UnsupportedOperationException: IteratorChains must
> contain at least one Iterator
>
> at
> org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
> Source)
>
> at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
> Source)
>
> at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
> Source)
>
> at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java
> :2196)
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
> :1809)
>
> ... 5 more
>
> <0.0.0 fatal store error> org.apache.openjpa.persistence.RollbackException:
> IteratorChains must contain at least one Iterator
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> EntityManagerImpl.java:420)
>
> at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)
>
> Caused by: <0.0.0 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: IteratorChains must
> contain at least one Iterator
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
> :1833)
>
> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> LocalManagedRuntime.java:93)
>
> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)
>
> at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
> :869)
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> EntityManagerImpl.java:409)
>
> ... 1 more
>
> Caused by: java.lang.UnsupportedOperationException: IteratorChains must
> contain at least one Iterator
>
> at
> org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
> Source)
>
> at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
> Source)
>
> at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
> Source)update different fields
>
> at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java
> :2196)
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
> :1809)
>
> ... 5 more
>
>
> On 6/19/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
> >
> >
> >    [
> > https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506312]
> >
> > Patrick Linskey commented on OPENJPA-261:
> > -----------------------------------------
> >
> > So you're saying that Collections.EMPTY_LIST.iterator() is returning
> > null? That seems surprising. What version of Java are you using? Can you
> > check if your Java version is returning null from
> > Collecitons.EMPTY_LIST.iterator ()?
> >
> > > NullPointerException occurred in BrokerImpl.java
> > > ------------------------------------------------
> > >
> > >                 Key: OPENJPA-261
> > >                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
> > >             Project: OpenJPA
> > >          Issue Type: Bug
> > >          Components: kernel
> > >    Affects Versions: 0.9.7
> > >         Environment: Window XP
> > >            Reporter: Teresa Kan
> > >            Priority: Critical
> > >         Attachments: NPE.patch
> > >
> > >
> > > While I was testing against the openjpa code, I got a NPE in the
> > BrokerImpl.endtransaction () method. The method set the transState to an
> > empty Collection if there is no cache for transactions. Later the code did
> > not check this Collection and tried to iterate on it and a
> > NullPointerException occurred.
> > > Original code:
> > > Collection transStates = _transCache;
> > >         if (transStates == null)
> > >             transStates = Collections.EMPTY_LIST;
> > > .....
> > > for (Iterator itr = transStates.iterator(); itr.hasNext ();) {  <---
> > NPE occurred here.
> > >             sm = (StateManagerImpl) itr.next();
> > >             try {
> > >                 if (rollback) {
> > >                     // tell objects that may have been derefed then
> > flushed
> > >                     // (and therefore deleted) to un-deref
> > >                     sm.setDereferencedDependent(false, false);
> > >                     sm.rollback();
> > >                 } else
> > >                     sm.commit();
> > >             } catch (RuntimeException re) {
> > >                 exceps = add(exceps, re);
> > >             }
> > >          }
> > > I put a check before this "for" loop then the NPE disappeared.
> > > if (!transStates.isEmpty()) {
> > >               for (Iterator itr = transStates.iterator(); itr.hasNext();)
> > {
> > >             sm = (StateManagerImpl) itr.next();
> > >             try {
> > >                 if (rollback) {
> > >                     // tell objects that may have been derefed then
> > flushed
> > >                     // (and therefore deleted) to un-deref
> > >                     sm.setDereferencedDependent(false, false);
> > >                     sm.rollback();
> > >                 } else
> > >                     sm.commit();
> > >             } catch (RuntimeException re) {
> > >                 exceps = add(exceps, re);
> > >             }
> > >          }
> > >         }
> > > The NPE.patch is attached in this jiar.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>

Re: [jira] Commented: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by Teresa Kan <tc...@gmail.com>.
Sorry it was not NPE, it was UnsupportedOperationException. I had the NPE
before and somehow mixed up with two. Anyway, it caused by :
java.lang.UnsupportedOperationException: IteratorChains must contain at
least one Iterator

The Collecitons.EMPTY_LIST.iterator() does not return null.
Here is the exception stack:

4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
ending the transaction. This exception will be re-thrown.

<0.0.0 nonfatal user error> org.apache.openjpa.util.NoTransactionException:
Can only perform operation while a transaction is active.

at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(
BrokerImpl.java:4307)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1806)

at org.apache.openjpa.kernel.LocalManagedRuntime.rollback(
LocalManagedRuntime.java:123)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:104)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
ending the transaction. This exception will be re-thrown.

<0.0.0 nonfatal store error> org.apache.openjpa.util.StoreException:
IteratorChains must contain at least one Iterator

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1833)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:93)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

Caused by: java.lang.UnsupportedOperationException: IteratorChains must
contain at least one Iterator

at
org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
Source)

at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java:2196)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1809)

... 5 more

<0.0.0 fatal store error> org.apache.openjpa.persistence.RollbackException:
IteratorChains must contain at least one Iterator

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:420)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

Caused by: <0.0.0 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: IteratorChains must
contain at least one Iterator

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1833)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:93)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

... 1 more

Caused by: java.lang.UnsupportedOperationException: IteratorChains must
contain at least one Iterator

at
org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
Source)update different fields

at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java:2196)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1809)

... 5 more


On 6/19/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
>
>
>    [
> https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506312]
>
> Patrick Linskey commented on OPENJPA-261:
> -----------------------------------------
>
> So you're saying that Collections.EMPTY_LIST.iterator() is returning null?
> That seems surprising. What version of Java are you using? Can you check if
> your Java version is returning null from Collecitons.EMPTY_LIST.iterator
> ()?
>
> > NullPointerException occurred in BrokerImpl.java
> > ------------------------------------------------
> >
> >                 Key: OPENJPA-261
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 0.9.7
> >         Environment: Window XP
> >            Reporter: Teresa Kan
> >            Priority: Critical
> >         Attachments: NPE.patch
> >
> >
> > While I was testing against the openjpa code, I got a NPE in the
> BrokerImpl.endtransaction() method. The method set the transState to an
> empty Collection if there is no cache for transactions. Later the code did
> not check this Collection and tried to iterate on it and a
> NullPointerException occurred.
> > Original code:
> > Collection transStates = _transCache;
> >         if (transStates == null)
> >             transStates = Collections.EMPTY_LIST;
> > .....
> > for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE
> occurred here.
> >             sm = (StateManagerImpl) itr.next();
> >             try {
> >                 if (rollback) {
> >                     // tell objects that may have been derefed then
> flushed
> >                     // (and therefore deleted) to un-deref
> >                     sm.setDereferencedDependent(false, false);
> >                     sm.rollback();
> >                 } else
> >                     sm.commit();
> >             } catch (RuntimeException re) {
> >                 exceps = add(exceps, re);
> >             }
> >          }
> > I put a check before this "for" loop then the NPE disappeared.
> > if (!transStates.isEmpty()) {
> >               for (Iterator itr = transStates.iterator(); itr.hasNext();)
> {
> >             sm = (StateManagerImpl) itr.next();
> >             try {
> >                 if (rollback) {
> >                     // tell objects that may have been derefed then
> flushed
> >                     // (and therefore deleted) to un-deref
> >                     sm.setDereferencedDependent(false, false);
> >                     sm.rollback();
> >                 } else
> >                     sm.commit();
> >             } catch (RuntimeException re) {
> >                 exceps = add(exceps, re);
> >             }
> >          }
> >         }
> > The NPE.patch is attached in this jiar.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Re: [jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by Teresa Kan <tc...@gmail.com>.
Here is the testcase zip file:

On 6/21/07, Teresa Kan <tc...@gmail.com> wrote:
>
> Patrick,
> After I applied your changes and I got the NPE in your changes:
>
>
> *
>
> if
> *((_dirty == *null* || _dirty.isEmpty()
>
> &&
> _clean == *null* || _clean .isEmpty()))
>
> Exception in thread "main" <0.0.0 fatal store error>
> *org.apache.openjpa.persistence.RollbackException* : null
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> *EntityManagerImpl.java:420*)
>
> at tutorial.ejb.TestEmpsPerClass.main(
> *TestEmpsPerClass.java:56*)
>
> Caused by: <0.0.0 nonfatal general error>
> *org.apache.openjpa.persistence.PersistenceException*: null
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(
> *BrokerImpl.java:1834*)
>
> at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
> *LocalManagedRuntime.java:93*)
>
> at org.apache.openjpa.kernel.BrokerImpl.commit(
> *BrokerImpl.java:1320*)
>
> at org.apache.openjpa.kernel.DelegatingBroker.commit(
> *DelegatingBroker.java:869*)
>
> at org.apache.openjpa.persistence.EntityManagerImpl.commit(
> *EntityManagerImpl.java:409*)
>
> ... 1 more
>
> Caused by:
> *java.lang.NullPointerException*
>
> at org.apache.openjpa.kernel.BrokerImpl$TransactionalCache.iterator(
> *BrokerImpl.java:4691*)
>
> at org.apache.openjpa.kernel.BrokerImpl.endTransaction(
> *BrokerImpl.java:2194*)
>
> at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(
> *BrokerImpl.java:1810*)
>
> On 6/20/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
> >
> >
> >     [
> > https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel]
> >
> > Patrick Linskey updated OPENJPA-261:
> > ------------------------------------
> >
> >    Attachment: OPENJPA-261-Java5.jar
> >                OPENJPA-261.patch
> >
> > So I saw exactly this problem a few days ago, and fixed the code that
> > was leading to the IteratorChain problem. Upon doing so, I just ended up
> > uncovering a new problem.
> >
> > Attached is a patch that gets past this exception; I expect that you
> > will just get a new exception, probably about the managed cache being
> > corrupt. Can you try it out?
> >
> > The jar contains a a compiled version of the patch; because of some
> > other changes that I'm working on in my environment, the jar has a
> > dependency on Java 5; if you are still using JDK1.4, you'll need to
> > manually apply the patch (or convince another OpenJPA developer to do so,
> > and post the jar). If you are using Java 5, just put the jar in the front of
> > your classpath, or update the contents of openjpa.jar with the classes
> > listed in the jar.
> >
> > Also, can you describe what your test case is doing, or better yet,
> > attach your test case to this issue?
> >
> > > UnsupportedOperationException occurred in BrokerImpl.java
> > > ---------------------------------------------------------
> > >
> > >                 Key: OPENJPA-261
> > >                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
> >
> > >             Project: OpenJPA
> > >          Issue Type: Bug
> > >          Components: kernel
> > >    Affects Versions: 0.9.7
> > >         Environment: Window XP
> > >            Reporter: Teresa Kan
> > >            Priority: Critical
> > >         Attachments: NPE.patch, OPENJPA-261-Java5.jar,
> > OPENJPA-261.patch
> > >
> > >
> > > While I was testing against the openjpa code, I got an
> > UnsupportedOperationException in the BrokerImpl.endtransaction() method.
> > The method set the transState to an empty Collection if there is no cache
> > for transactions. Later the code got an UnsupportedOperationException.
> > > Original code:
> > > Collection transStates = _transCache;
> > >         if (transStates == null)
> > >             transStates = Collections.EMPTY_LIST;
> > > .....
> > > for (Iterator itr = transStates.iterator(); itr.hasNext();) {
> > >             sm = (StateManagerImpl) itr.next();
> > >             try {
> > >                 if (rollback) {
> > >                     // tell objects that may have been derefed then
> > flushed
> > >                     // (and therefore deleted) to un-deref
> > >                     sm.setDereferencedDependent(false, false);
> > >                     sm.rollback();
> > >                 } else
> > >                     sm.commit();
> > >             } catch (RuntimeException re) {
> > >                 exceps = add(exceps, re);
> > >             }
> > >          }
> > > I put a check before this "for" loop then the
> > UnsupportedOperationException
> > > disappeared.
> > > if (!transStates.isEmpty()) {
> > >               for (Iterator itr = transStates.iterator(); itr.hasNext();)
> > {
> > >             sm = (StateManagerImpl) itr.next();
> > >             try {
> > >                 if (rollback) {
> > >                     // tell objects that may have been derefed then
> > flushed
> > >                     // (and therefore deleted) to un-deref
> > >                     sm.setDereferencedDependent(false, false);
> > >                     sm.rollback();
> > >                 } else
> > >                     sm.commit();
> > >             } catch (RuntimeException re) {
> > >                 exceps = add(exceps, re);
> > >             }
> > >          }
> > >         }
> > > The NPE.patch is attached to this JIRA.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>

Re: [jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by Teresa Kan <tc...@gmail.com>.
Patrick,
After I applied your changes and I got the NPE in your changes:


*

if* ((_dirty == *null* || _dirty.isEmpty()

&& _clean == *null* || _clean.isEmpty()))

Exception in thread "main" <0.0.0 fatal store error> *
org.apache.openjpa.persistence.RollbackException*: null

at org.apache.openjpa.persistence.EntityManagerImpl.commit(*
EntityManagerImpl.java:420*)

at tutorial.ejb.TestEmpsPerClass.main(*TestEmpsPerClass.java:56*)

Caused by: <0.0.0 nonfatal general error> *
org.apache.openjpa.persistence.PersistenceException*: null

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(*BrokerImpl.java
:1834*)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(*
LocalManagedRuntime.java:93*)

at org.apache.openjpa.kernel.BrokerImpl.commit(*BrokerImpl.java:1320*)

at org.apache.openjpa.kernel.DelegatingBroker.commit(*DelegatingBroker.java
:869*)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(*
EntityManagerImpl.java:409*)

... 1 more

Caused by: *java.lang.NullPointerException
*

at org.apache.openjpa.kernel.BrokerImpl$TransactionalCache.iterator(*
BrokerImpl.java:4691*)

at org.apache.openjpa.kernel.BrokerImpl.endTransaction(*BrokerImpl.java:2194
*)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(*BrokerImpl.java
:1810*)


On 6/20/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote:
>
>
>     [
> https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel]
>
> Patrick Linskey updated OPENJPA-261:
> ------------------------------------
>
>    Attachment: OPENJPA-261-Java5.jar
>                OPENJPA-261.patch
>
> So I saw exactly this problem a few days ago, and fixed the code that was
> leading to the IteratorChain problem. Upon doing so, I just ended up
> uncovering a new problem.
>
> Attached is a patch that gets past this exception; I expect that you will
> just get a new exception, probably about the managed cache being corrupt.
> Can you try it out?
>
> The jar contains a a compiled version of the patch; because of some other
> changes that I'm working on in my environment, the jar has a dependency on
> Java 5; if you are still using JDK1.4, you'll need to manually apply the
> patch (or convince another OpenJPA developer to do so, and post the jar). If
> you are using Java 5, just put the jar in the front of your classpath, or
> update the contents of openjpa.jar with the classes listed in the jar.
>
> Also, can you describe what your test case is doing, or better yet, attach
> your test case to this issue?
>
> > UnsupportedOperationException occurred in BrokerImpl.java
> > ---------------------------------------------------------
> >
> >                 Key: OPENJPA-261
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 0.9.7
> >         Environment: Window XP
> >            Reporter: Teresa Kan
> >            Priority: Critical
> >         Attachments: NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
> >
> >
> > While I was testing against the openjpa code, I got an
> UnsupportedOperationException in the BrokerImpl.endtransaction() method.
> The method set the transState to an empty Collection if there is no cache
> for transactions. Later the code got an UnsupportedOperationException.
> > Original code:
> > Collection transStates = _transCache;
> >         if (transStates == null)
> >             transStates = Collections.EMPTY_LIST;
> > .....
> > for (Iterator itr = transStates.iterator(); itr.hasNext();) {
> >             sm = (StateManagerImpl) itr.next();
> >             try {
> >                 if (rollback) {
> >                     // tell objects that may have been derefed then
> flushed
> >                     // (and therefore deleted) to un-deref
> >                     sm.setDereferencedDependent(false, false);
> >                     sm.rollback();
> >                 } else
> >                     sm.commit();
> >             } catch (RuntimeException re) {
> >                 exceps = add(exceps, re);
> >             }
> >          }
> > I put a check before this "for" loop then the
> UnsupportedOperationException
> > disappeared.
> > if (!transStates.isEmpty()) {
> >               for (Iterator itr = transStates.iterator(); itr.hasNext();)
> {
> >             sm = (StateManagerImpl) itr.next();
> >             try {
> >                 if (rollback) {
> >                     // tell objects that may have been derefed then
> flushed
> >                     // (and therefore deleted) to un-deref
> >                     sm.setDereferencedDependent(false, false);
> >                     sm.rollback();
> >                 } else
> >                     sm.commit();
> >             } catch (RuntimeException re) {
> >                 exceps = add(exceps, re);
> >             }
> >          }
> >         }
> > The NPE.patch is attached to this JIRA.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Commented: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506936 ] 

Teresa Kan commented on OPENJPA-261:
------------------------------------

Patrick,
After I applied your changes and I got the NPE in your changes:

if ((_dirty == null || _dirty.isEmpty() 
&& 
_clean == null || _clean .isEmpty())) 


Exception in thread "main" <0.0.0 fatal store error> 

org.apache.openjpa.persistence.RollbackException : null 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:420) 
at tutorial.ejb.TestEmpsPerClass.main(

TestEmpsPerClass.java:56) 
Caused by: <0.0.0 nonfatal general error> 

org.apache.openjpa.persistence.PersistenceException: null 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1834) 
at org.apache.openjpa.kernel.LocalManagedRuntime.commit(

LocalManagedRuntime.java:93) 
at org.apache.openjpa.kernel.BrokerImpl.commit(

BrokerImpl.java:1320) 
at org.apache.openjpa.kernel.DelegatingBroker.commit(

DelegatingBroker.java:869) 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:409) 
... 1 more

Caused by: 

java.lang.NullPointerException 
at org.apache.openjpa.kernel.BrokerImpl$TransactionalCache.iterator(

BrokerImpl.java:4691) 
at org.apache.openjpa.kernel.BrokerImpl.endTransaction(

BrokerImpl.java:2194) 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1810) 
- Show quoted text -

I attached the testcase JIAR261_test.zip file here.
 
On 6/20/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote: 

    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey updated OPENJPA-261:
------------------------------------

   Attachment: OPENJPA-261-Java5.jar
               OPENJPA-261.patch

So I saw exactly this problem a few days ago, and fixed the code that was leading to the IteratorChain problem. Upon doing so, I just ended up uncovering a new problem. 

Attached is a patch that gets past this exception; I expect that you will just get a new exception, probably about the managed cache being corrupt. Can you try it out?

The jar contains a a compiled version of the patch; because of some other changes that I'm working on in my environment, the jar has a dependency on Java 5; if you are still using JDK1.4, you'll need to manually apply the patch (or convince another OpenJPA developer to do so, and post the jar). If you are using Java 5, just put the jar in the front of your classpath, or update the contents of openjpa.jar with the classes listed in the jar.

Also, can you describe what your test case is doing, or better yet, attach your test case to this issue?

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261 
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan 
>            Priority: Critical
>         Attachments: NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache; 
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref 
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) { 
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) { 
>               for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed 
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.





> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: JIAR261_test.zip, NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506312 ] 

Patrick Linskey commented on OPENJPA-261:
-----------------------------------------

So you're saying that Collections.EMPTY_LIST.iterator() is returning null? That seems surprising. What version of Java are you using? Can you check if your Java version is returning null from Collecitons.EMPTY_LIST.iterator()?

> NullPointerException occurred in BrokerImpl.java
> ------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got a NPE in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code did not check this Collection and tried to iterate on it and a NullPointerException occurred.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the NPE disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached in this jiar. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506371 ] 

Craig Russell commented on OPENJPA-261:
---------------------------------------

There is still something fishy about the reported symptoms. With an empty collection, the itr.hasNext() will return false, and the for loop will never be executed. So the problem must be further down where the transStates empty collection is being used.

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506401 ] 

Patrick Linskey commented on OPENJPA-261:
-----------------------------------------

Update from Teresa's email:

Sorry it was not NPE, it was UnsupportedOperationException. I had the NPE
before and somehow mixed up with two. Anyway, it caused by :
java.lang.UnsupportedOperationException: IteratorChains must contain at
least one Iterator

The Collecitons.EMPTY_LIST.iterator() does not return null.
Here is the exception stack:

4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
ending the transaction. This exception will be re-thrown.

<0.0.0 nonfatal user error> org.apache.openjpa.util.NoTransactionException:
Can only perform operation while a transaction is active.

at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(
BrokerImpl.java:4307)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1806)

at org.apache.openjpa.kernel.LocalManagedRuntime.rollback(
LocalManagedRuntime.java:123)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:104)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

4781 emptest TRACE [main] openjpa.Runtime - An exception occurred while
ending the transaction. This exception will be re-thrown.

<0.0.0 nonfatal store error> org.apache.openjpa.util.StoreException:
IteratorChains must contain at least one Iterator

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1833)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:93)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

Caused by: java.lang.UnsupportedOperationException: IteratorChains must
contain at least one Iterator

at
org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
Source)

at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java:2196)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1809)

... 5 more

<0.0.0 fatal store error> org.apache.openjpa.persistence.RollbackException:
IteratorChains must contain at least one Iterator

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:420)

at tutorial.ejb.TestEmpsPerClass.main(TestEmpsPerClass.java:135)

Caused by: <0.0.0 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: IteratorChains must
contain at least one Iterator

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1833)

at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
LocalManagedRuntime.java:93)

at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1319)

at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java
:869)

at org.apache.openjpa.persistence.EntityManagerImpl.commit(
EntityManagerImpl.java:409)

... 1 more

Caused by: java.lang.UnsupportedOperationException: IteratorChains must
contain at least one Iterator

at
org.apache.commons.collections.iterators.IteratorChain.checkChainIntegrity(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.lockChain(Unknown
Source)

at org.apache.commons.collections.iterators.IteratorChain.hasNext(Unknown
Source)update different fields

at org.apache.openjpa.kernel.BrokerImpl.endTransaction(BrokerImpl.java:2196)

at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(BrokerImpl.java
:1809)

... 5 more


> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Craig Russell updated OPENJPA-261:
----------------------------------

    Description: 
While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.

Original code:

Collection transStates = _transCache;
        if (transStates == null)
            transStates = Collections.EMPTY_LIST;
.....
for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }

I put a check before this "for" loop then the NPE disappeared.

if (!transStates.isEmpty()) {   
        	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }
        }
The NPE.patch is attached in this jiar. 

  was:
While I was testing against the openjpa code, I got a NPE in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code did not check this Collection and tried to iterate on it and a NullPointerException occurred.

Original code:

Collection transStates = _transCache;
        if (transStates == null)
            transStates = Collections.EMPTY_LIST;
.....
for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }

I put a check before this "for" loop then the NPE disappeared.

if (!transStates.isEmpty()) {   
        	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }
        }
The NPE.patch is attached in this jiar. 

        Summary: UnsupportedOperationException occurred in BrokerImpl.java  (was: NullPointerException occurred in BrokerImpl.java)

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the NPE disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached in this jiar. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan closed OPENJPA-261.
------------------------------

    Resolution: Fixed

It seems to me that the bug was fixed in the recent OPENJPA build. So close this issue.

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: JIAR261_test.zip, NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-261) NullPointerException occurred in BrokerImpl.java

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-261:
-------------------------------

    Attachment: NPE.patch

Patch for OPENJPA-261

> NullPointerException occurred in BrokerImpl.java
> ------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got a NPE in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code did not check this Collection and tried to iterate on it and a NullPointerException occurred.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the NPE disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached in this jiar. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Craig Russell updated OPENJPA-261:
----------------------------------

    Description: 
While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.

Original code:

Collection transStates = _transCache;
        if (transStates == null)
            transStates = Collections.EMPTY_LIST;
.....
for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }

I put a check before this "for" loop then the UnsupportedOperationException
disappeared.
if (!transStates.isEmpty()) {   
        	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }
        }
The NPE.patch is attached to this JIRA. 

  was:
While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.

Original code:

Collection transStates = _transCache;
        if (transStates == null)
            transStates = Collections.EMPTY_LIST;
.....
for (Iterator itr = transStates.iterator(); itr.hasNext();) {  <--- NPE occurred here.
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }

I put a check before this "for" loop then the NPE disappeared.

if (!transStates.isEmpty()) {   
        	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
            sm = (StateManagerImpl) itr.next();
            try {
                if (rollback) {
                    // tell objects that may have been derefed then flushed
                    // (and therefore deleted) to un-deref
                    sm.setDereferencedDependent(false, false);
                    sm.rollback();
                } else
                    sm.commit();
            } catch (RuntimeException re) {
                exceps = add(exceps, re);
            }
         }
        }
The NPE.patch is attached in this jiar. 


> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506936 ] 

Teresa Kan edited comment on OPENJPA-261 at 6/21/07 8:40 AM:
-------------------------------------------------------------

Patrick,
After I applied your changes and I got the NPE in your changes:

if ((_dirty == null || _dirty.isEmpty() 
&& 
_clean == null || _clean .isEmpty())) 


Exception in thread "main" <0.0.0 fatal store error> 

org.apache.openjpa.persistence.RollbackException : null 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:420) 
at tutorial.ejb.TestEmpsPerClass.main(

TestEmpsPerClass.java:56) 
Caused by: <0.0.0 nonfatal general error> 

org.apache.openjpa.persistence.PersistenceException: null 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1834) 
at org.apache.openjpa.kernel.LocalManagedRuntime.commit(

LocalManagedRuntime.java:93) 
at org.apache.openjpa.kernel.BrokerImpl.commit(

BrokerImpl.java:1320) 
at org.apache.openjpa.kernel.DelegatingBroker.commit(

DelegatingBroker.java:869) 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:409) 
... 1 more

Caused by: 

java.lang.NullPointerException 
at org.apache.openjpa.kernel.BrokerImpl$TransactionalCache.iterator(

BrokerImpl.java:4691) 
at org.apache.openjpa.kernel.BrokerImpl.endTransaction(

BrokerImpl.java:2194) 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1810) 
- Show quoted text -

I attached the testcase JIAR261_test.zip file here.
 



 was:
Patrick,
After I applied your changes and I got the NPE in your changes:

if ((_dirty == null || _dirty.isEmpty() 
&& 
_clean == null || _clean .isEmpty())) 


Exception in thread "main" <0.0.0 fatal store error> 

org.apache.openjpa.persistence.RollbackException : null 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:420) 
at tutorial.ejb.TestEmpsPerClass.main(

TestEmpsPerClass.java:56) 
Caused by: <0.0.0 nonfatal general error> 

org.apache.openjpa.persistence.PersistenceException: null 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1834) 
at org.apache.openjpa.kernel.LocalManagedRuntime.commit(

LocalManagedRuntime.java:93) 
at org.apache.openjpa.kernel.BrokerImpl.commit(

BrokerImpl.java:1320) 
at org.apache.openjpa.kernel.DelegatingBroker.commit(

DelegatingBroker.java:869) 
at org.apache.openjpa.persistence.EntityManagerImpl.commit(

EntityManagerImpl.java:409) 
... 1 more

Caused by: 

java.lang.NullPointerException 
at org.apache.openjpa.kernel.BrokerImpl$TransactionalCache.iterator(

BrokerImpl.java:4691) 
at org.apache.openjpa.kernel.BrokerImpl.endTransaction(

BrokerImpl.java:2194) 
at org.apache.openjpa.kernel.BrokerImpl.afterCompletion(

BrokerImpl.java:1810) 
- Show quoted text -

I attached the testcase JIAR261_test.zip file here.
 
On 6/20/07, Patrick Linskey (JIRA) <ji...@apache.org> wrote: 

    [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey updated OPENJPA-261:
------------------------------------

   Attachment: OPENJPA-261-Java5.jar
               OPENJPA-261.patch

So I saw exactly this problem a few days ago, and fixed the code that was leading to the IteratorChain problem. Upon doing so, I just ended up uncovering a new problem. 

Attached is a patch that gets past this exception; I expect that you will just get a new exception, probably about the managed cache being corrupt. Can you try it out?

The jar contains a a compiled version of the patch; because of some other changes that I'm working on in my environment, the jar has a dependency on Java 5; if you are still using JDK1.4, you'll need to manually apply the patch (or convince another OpenJPA developer to do so, and post the jar). If you are using Java 5, just put the jar in the front of your classpath, or update the contents of openjpa.jar with the classes listed in the jar.

Also, can you describe what your test case is doing, or better yet, attach your test case to this issue?

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261 
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan 
>            Priority: Critical
>         Attachments: NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache; 
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref 
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) { 
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) { 
>               for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed 
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.





> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: JIAR261_test.zip, NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-261:
-------------------------------

    Attachment: JIAR261_test.zip

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: JIAR261_test.zip, NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-261) UnsupportedOperationException occurred in BrokerImpl.java

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey updated OPENJPA-261:
------------------------------------

    Attachment: OPENJPA-261-Java5.jar
                OPENJPA-261.patch

So I saw exactly this problem a few days ago, and fixed the code that was leading to the IteratorChain problem. Upon doing so, I just ended up uncovering a new problem.

Attached is a patch that gets past this exception; I expect that you will just get a new exception, probably about the managed cache being corrupt. Can you try it out?

The jar contains a a compiled version of the patch; because of some other changes that I'm working on in my environment, the jar has a dependency on Java 5; if you are still using JDK1.4, you'll need to manually apply the patch (or convince another OpenJPA developer to do so, and post the jar). If you are using Java 5, just put the jar in the front of your classpath, or update the contents of openjpa.jar with the classes listed in the jar.

Also, can you describe what your test case is doing, or better yet, attach your test case to this issue?

> UnsupportedOperationException occurred in BrokerImpl.java
> ---------------------------------------------------------
>
>                 Key: OPENJPA-261
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-261
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.7
>         Environment: Window XP
>            Reporter: Teresa Kan
>            Priority: Critical
>         Attachments: NPE.patch, OPENJPA-261-Java5.jar, OPENJPA-261.patch
>
>
> While I was testing against the openjpa code, I got an UnsupportedOperationException in the BrokerImpl.endtransaction() method. The method set the transState to an empty Collection if there is no cache for transactions. Later the code got an UnsupportedOperationException.
> Original code:
> Collection transStates = _transCache;
>         if (transStates == null)
>             transStates = Collections.EMPTY_LIST;
> .....
> for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
> I put a check before this "for" loop then the UnsupportedOperationException
> disappeared.
> if (!transStates.isEmpty()) {   
>         	for (Iterator itr = transStates.iterator(); itr.hasNext();) {
>             sm = (StateManagerImpl) itr.next();
>             try {
>                 if (rollback) {
>                     // tell objects that may have been derefed then flushed
>                     // (and therefore deleted) to un-deref
>                     sm.setDereferencedDependent(false, false);
>                     sm.rollback();
>                 } else
>                     sm.commit();
>             } catch (RuntimeException re) {
>                 exceps = add(exceps, re);
>             }
>          }
>         }
> The NPE.patch is attached to this JIRA. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.