Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Yikes! ConcurrentModificationException
Yikes! ConcurrentModificationException [message #384217] Thu, 04 December 2008 13:37 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
Can something in my code cause this???

java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractLi st.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at org.eclipse.persistence.indirection.IndirectList$1.next(Indi rectList.java:546)
at org.eclipse.persistence.internal.queries.InterfaceContainerP olicy.next(InterfaceContainerPolicy.java:226)
at org.eclipse.persistence.internal.queries.ContainerPolicy.nex t(ContainerPolicy.java:701)
at org.eclipse.persistence.mappings.CollectionMapping.cascadeDi scoverAndPersistUnregisteredNewObjects(CollectionMapping.jav a:251)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.c ascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder .java:1489)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.dis coverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:37 99)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOf Work.java:181)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.cal culateChanges(UnitOfWorkImpl.java:584)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1320)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java: 159)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitAndResume(UnitOfWorkImpl.java:1002)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(EntityTransactionImpl.java:84)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commit(EntityTransactionImpl.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.tbee.util.jpa.EntityTransactionExtender.invoke(EntityTra nsactionExtender.java:106)
at $Proxy36.commit(Unknown Source)
at org.tbee.swing.jpa.JpaObjectNavigatorModel.doSave(JpaObjectN avigatorModel.java:746)
at org.tbee.swing.jpa.JpaObjectNavigatorBar$3.actionPerformed(J paObjectNavigatorBar.java:125)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButto n.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractB utton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultBu ttonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel .java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Bas icButtonListener.java:236)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticast er.java:272)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:326 5)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container. java:4301)
at java.awt.LightweightDispatcher.processMouseEvent(Container.j ava:3965)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java: 3895)
at java.awt.Container.dispatchEventImpl(Container.java:2067)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at org.tbee.swing.EventQueue.dispatchEvent(EventQueue.java:83)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDis patchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispat chThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDis patchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:12 2)
Re: Yikes! ConcurrentModificationException [message #384222 is a reply to message #384217] Thu, 04 December 2008 14:18 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This is an odd one. It looks like that during the cascade of persist of
your collection mapping something is occurring to change the collection be
iterated over. My guess is you have some prePersist event that is being
fired that is modifying the collection. Probably not a good idea.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: Yikes! ConcurrentModificationException [message #384225 is a reply to message #384217] Thu, 04 December 2008 14:26 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
Appearantly it can, if I revert my BM back to yesterday, it is gone. Now to find out what causes it.
Re: Yikes! ConcurrentModificationException [message #384227 is a reply to message #384225] Thu, 04 December 2008 14:56 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
tbee wrote:
> Appearantly it can, if I revert my BM back to yesterday, it is gone. Now
> to find out what causes it.

Found the culprit (<-----). Upon instance creation, one of the properties is set with a default entity. If I comment that line out, things are working fine. I do not understand why yet, though.

/**
*
*/
public Buyorder()
{
ignoreChanges();
try
{
defaults();
}
finally
{
registerChanges();
}
}

/**
* defaults
*/
private void defaults()
{
setBuydate(java.util.Calendar.getInstance());
setStage(STAGE_ENTERED);
setReindersRelation(Relation.findReindersNetherlands()); // <--------------
}

FYI:
/** disable the change detection (for defaults in the constructor), ignoreChanges and registerChanges must be balanced! */
public void ignoreChanges() { iIgnoreChangesGate.incrementAndGet(); }
public void registerChanges() { iIgnoreChangesGate.decrementAndGet(); }
@Transient transient volatile private AtomicInteger iIgnoreChangesGate = new AtomicInteger();

And:
static public Relation findReindersNetherlands() { return findByPK(10060); }

And:
static public nl.reinders.bm.Relation findByPK(java.math.BigInteger relationnr)
{
EntityManager lEntityManager = org.tbee.util.jpa.EntityManagerFinder.findEntityManager();
if ( lEntityManager == null) return null;
if (log4j.isDebugEnabled()) log4j.debug("Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
Query lQuery = lEntityManager.createQuery("select t from Relation t where t.iRelationnr=:relationnr");

lQuery.setParameter("relationnr", relationnr);
java.util.List<nl.reinders.bm.Relation> lList = lQuery.getResultList();
if (lList.size() == 0) return null;
return lList.get(0);
}
Re: Yikes! ConcurrentModificationException [message #384229 is a reply to message #384227] Thu, 04 December 2008 15:12 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
Zooming in on Buyorder... The error is caused by this line:

public void setReindersRelation(nl.reinders.bm.Relation value)
{
if (value == iReindersRelation) return; // optimalisation and prevent looping
nl.reinders.bm.Relation lValue = iReindersRelation;
if (log4j.isDebugEnabled()) log4j.debug("setReindersRelation: " + lValue + " -> " + value);
fireVetoableChange(REINDERSRELATION_PROPERTY_ID, lValue, value);
if (lValue != null) lValue.removeBuyordersWhereIAmReindersRelation( (nl.reinders.bm.Buyorder)this );
iReindersRelation = value;
try {
if (value != null) value.addBuyordersWhereIAmReindersRelation( (nl.reinders.bm.Buyorder)this ); // <----------------------
} catch (RuntimeException e) { iReindersRelation = lValue; throw e; } // restore upon exception
firePropertyChange(REINDERSRELATION_PROPERTY_ID, lValue, value);
}

So, if a buyorder is created, it searches for a specific relation as a default value, sets it and because of the 1-N, that buyorder is also added to the relation's collection.

Zooming in again on Relation:

public void addBuyordersWhereIAmReindersRelation(nl.reinders.bm.Buyorder value)
{
if (value != null && !iBuyordersWhereIAmReindersRelation.contains(value))
{
java.util.List<nl.reinders.bm.Buyorder> lValue = new java.util.ArrayList<nl.reinders.bm.Buyorder>();
lValue.addAll(iBuyordersWhereIAmReindersRelation);
lValue.add(value);
fireVetoableChange(BUYORDERSWHEREIAMREINDERSRELATION_PROPERT Y_ID, java.util.Collections.unmodifiableList(iBuyordersWhereIAmRei ndersRelation), java.util.Collections.unmodifiableList(lValue));
boolean lWasAdded = iBuyordersWhereIAmReindersRelation.add(value); // <----------------------
lValue.remove(value);
firePropertyChange(BUYORDERSWHEREIAMREINDERSRELATION_PROPERT Y_ID, java.util.Collections.unmodifiableList(lValue), java.util.Collections.unmodifiableList(iBuyordersWhereIAmRei ndersRelation));
try {
value.setReindersRelation( (nl.reinders.bm.Relation)this);
} catch (RuntimeException e) { if (lWasAdded) {iBuyordersWhereIAmReindersRelation.remove(value);} throw e; } // restore upon exception
}
}

If the add is commented out, the error does not occur.

For the CME to occur, it must be processing the iBuyordersWhereIAmReindersRelation. In what way will processing the iBuyordersWhereIAmReindersRelation create a new Buyorder instance?
Re: Yikes! ConcurrentModificationException [message #384231 is a reply to message #384229] Thu, 04 December 2008 15:59 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
Here also I had to revoke to an application level event:

@Override public void postNew(Buyorder e)
{
e.ignoreChanges();
try
{
e.setReindersRelation(Relation.findReindersNetherlands());
}
finally
{
e.registerChanges();
}
}

I really really have to think about that AspectJ approach.
Previous Topic:A NullPointerException was thrown while extracting a value from the instance variable [amount] in th
Next Topic:Entity must be managed to call remove
Goto Forum:
  


Current Time: Mon Nov 24 23:03:46 GMT 2014

Powered by FUDForum. Page generated in 0.07054 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software