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

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

     [ 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.