Hi. 

I found another possible bug in the UnitOfWorkCallback handling code. I don´t 
have time to write a testcase now, so I´ll try to explain it. 

Problem:

If an entity which implements UnitOfWorkCallback loads any entities in the 
callback method which haven´t already been loaded into the current unit of work 
(either by traversing an association that is lazy loaded or by directly loading 
other entities by other means) it leads to a 
java.util.ConcurrentModificationException in the notifyBeforeCompletion method 
of UnitOfWorkInstance. 

Proposed solution: 
 
I think it would be possible to avoid this problem by making a copy of the 
entityInstances map before iterating it in the notifyBeforeCompletion method of 
UnitOfWorkInstance. 

 private void notifyBeforeCompletion( List<UnitOfWorkCallback> callbacks )
            throws UnitOfWorkCompletionException
    {
        // Notify explicitly registered callbacks
        if( callbacks != null )
        {
            for (UnitOfWorkCallback callback : callbacks)
            {
                callback.beforeCompletion();
            }
        }

        // Notify entities
        try
        {
            new ForEachEntity()
            {
                protected void execute( EntityInstance instance )
                        throws Exception
                {
                    if( instance.<Object>proxy() instanceof UnitOfWorkCallback 
&& !instance.status().equals(EntityStatus.REMOVED))
                    {
                        UnitOfWorkCallback callback = 
UnitOfWorkCallback.class.cast( instance.proxy() );
                        callback.beforeCompletion();
                    }
                }
            }.execute();
        }
        catch (UnitOfWorkCompletionException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new UnitOfWorkCompletionException( e );
        }
    }

Let me know if you need any more info on this issue. 



Regards
Webstep AS
 
RONNIE NESSA  |  Senior consultant
Mob : +47 970 69 512  | [email protected]
www.webstep.no




_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to