Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#300 closed defect (fixed)

Restore IDE warning for enhanced loop when updating collection, array or list has side effects

Reported by: Fxp Owned by: heikki
Priority: major Milestone:
Component: General Version: v2.6.0RC1
Keywords: Cc:

Description

Removing an element could trigger ConcurrentModificationException on DataManager.deleteElementEmbedded when the element is deleted in the DOM.

Example exception (provided by Justin Rowles)

2010-08-27 10:52:48,369 INFO  [jeeves.service] - Dispatching : metadata.elem.delete
2010-08-27 10:52:48,369 DEBUG [jeeves.service] -  -> parameters are :
<request>
  <id>2</id>
  <ref>18</ref>
  <parent>15</parent>
  <_dc>1282902768374</_dc>
</request>
2010-08-27 10:52:48,369 ERROR [jeeves.service] - Exception when executing service
2010-08-27 10:52:48,369 ERROR [jeeves.service] -  (C) Exc : java.util.ConcurrentModificationException
2010-08-27 10:52:48,369 DEBUG [jeeves.service] - Raised exception while executing service
<error id="error">
  <message />
  <class>ConcurrentModificationException</class>
  <stack>
    <at class="org.jdom.ContentList$FilterListIterator" file="ContentList.java"
line="1041" method="checkConcurrentModification" />
    <at class="org.jdom.ContentList$FilterListIterator" file="ContentList.java"
line="752" method="hasNext" />
    <at class="org.fao.geonet.kernel.DataManager" file="DataManager.java" line="1388" method="deleteElementEmbedded" />
    <at class="org.fao.geonet.services.metadata.DeleteElement" file="DeleteElement.java" line="72" method="exec" />
    <at class="jeeves.server.dispatchers.ServiceInfo" file="ServiceInfo.java" line="238" method="execService" />
    <at class="jeeves.server.dispatchers.ServiceInfo" file="ServiceInfo.java" line="141" method="execServices" />
    <at class="jeeves.server.dispatchers.ServiceManager" file="ServiceManager.java" line="396" method="dispatch" />
    <at class="jeeves.server.JeevesEngine" file="JeevesEngine.java" line="624" method="dispatch" />
    <at class="jeeves.server.sources.http.JeevesServlet" file="JeevesServlet.java" line="185" method="execute" />
    <at class="jeeves.server.sources.http.JeevesServlet" file="JeevesServlet.java" line="98" method="doGet" />
  </stack>
  <request>
    <language>en</language>
    <service>metadata.elem.delete</service>
  </request>
</error>
2010-08-27 10:52:48,369 INFO  [jeeves.service] -    -> dispatching to error for: metadata.elem.delete
2010-08-27 10:52:48,385 INFO  [jee

Restoring the old style for loop fix that issue.

The reason looks to be the following:

It's important to note that the enhanced for loop can't be used everywhere. You can't use the enhanced for loop:

 * To remove elements as you traverse collections
 * To modify the current slot in an array or list
 * To iterate over multiple collections or arrays

See http://www.java-tips.org/java-se-tips/java.lang/the-enhanced-for-loop.html

Probably the "addressing IDE warning commit" needs a review to check that we do not have any other side effects ?

Change History (2)

comment:1 by heikki, 13 years ago

Resolution: fixed
Status: newclosed

As far as is known, this doesn't happen anywhere in the GN code anymore. If we still find it let's create dedicated tickets for that.

Note: See TracTickets for help on using tickets.