Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351186 - ConcurrentModificationException Exception in PropertiesHandler
Summary: ConcurrentModificationException Exception in PropertiesHandler
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-05 09:23 EDT by Eduard Bartsch CLA
Modified: 2022-06-09 10:32 EDT (History)
2 users (show)

See Also:


Attachments
stack trace (11.65 KB, text/plain)
2011-07-05 09:23 EDT, Eduard Bartsch CLA
no flags Details
setup to reproduce the issue (9.88 KB, application/x-zip-compressed)
2011-07-05 09:25 EDT, Eduard Bartsch CLA
no flags Details
patch proposal (2.32 KB, patch)
2011-07-05 09:27 EDT, Eduard Bartsch CLA
no flags Details | Diff
updated patch proposal (2.35 KB, patch)
2011-07-14 04:43 EDT, Eduard Bartsch CLA
no flags Details | Diff
patch proposal V3 (1.85 KB, patch)
2011-07-22 03:49 EDT, Eduard Bartsch CLA
tom.ware: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eduard Bartsch CLA 2011-07-05 09:23:26 EDT
Created attachment 199121 [details]
stack trace

We are currently running into a concurrency issue during initialisation of EclipseLink/Gemini JPA that happens from time to time depending on timing.

Our application asynchronously modifies system properties during startup. If, by chance, EclipseLink/Gemini JPA initialisation happens at the same time, an exception is thrown and EntityManagerFactory is not returned.

Here is an excerpt of the stack trace:
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - @VERSION@.@QUALIFIER@): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [TestPersistenceUnit] failed.
Internal Exception: java.util.ConcurrentModificationException
	at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
	... 31 more
Caused by: java.util.ConcurrentModificationException
	at java.util.Hashtable$Enumerator.next(Hashtable.java:1031)
	at org.eclipse.persistence.internal.sessions.PropertiesHandler$Prop.getPrefixValuesFromMap(PropertiesHandler.java:233)
	at org.eclipse.persistence.internal.sessions.PropertiesHandler$Prop.getPrefixValuesToApply(PropertiesHandler.java:291)
	at org.eclipse.persistence.internal.sessions.PropertiesHandler.getPrefixValuesLogDebug(PropertiesHandler.java:140)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initOrUpdateLogging(EntityManagerSetupImpl.java:1982)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateLoggers(EntityManagerSetupImpl.java:730)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1147)
	... 30 more

I will attach the full stack trace and the zip file with a workspace setup that can be used to reproduce the situation.
Comment 1 Eduard Bartsch CLA 2011-07-05 09:25:07 EDT
Created attachment 199122 [details]
setup to reproduce the issue

Here is a ZIP file with two projects that can be used to reproduce the issue.
Comment 2 Eduard Bartsch CLA 2011-07-05 09:27:45 EDT
Created attachment 199123 [details]
patch proposal

Here is a patch proposal created on 2.3 branch. We would like to see the fix included into 2.3.1.
Comment 3 Tom Ware CLA 2011-07-06 11:16:37 EDT
My concern about this patch is there is no upper bound on the number of iterations in the loop.  As a result, if the ConcurrentModificationException is happening for some reason we have not anticipated, this will potentially lock up the application.
Comment 4 Eduard Bartsch CLA 2011-07-14 04:43:49 EDT
Created attachment 199639 [details]
updated patch proposal

Here is an updated patch with termination of the loop after 100 times.
Comment 5 Tom Ware CLA 2011-07-15 10:53:40 EDT
I will take a look - assigned to myself.
Comment 6 Tom Ware CLA 2011-07-20 10:13:07 EDT
Discussed with Shaun Smith: I think his suggestion is an improvement:

The right solution is to not get an iterator() for the entry set but to get an array via toArray().  toArray() will be synchronized on the properties *HashTable*.  Once we have a clean copy of the entries we can iterate over that without having to worry about modifications to the System.properties.
Comment 7 Eduard Bartsch CLA 2011-07-22 03:49:18 EDT
Created attachment 200153 [details]
patch proposal V3

Shaun's proposal is definitely the best one. Thanks.

Here is the updated patch that reflects the proposal.
Comment 8 Eduard Bartsch CLA 2011-08-09 06:46:56 EDT
Tom,

will you have time to review the patch and include it into 2.3.1?

Thanks and best regards, Ed
Comment 9 Tom Ware CLA 2011-08-09 08:12:43 EDT
My current plan is to look at this fairly soon and get it included in 2.3.1.
Comment 10 Tom Ware CLA 2011-08-09 15:58:40 EDT
Submitting fix without regression test case - our regression framework currently won't handle the scenario described above.

Checked into 2.3.1 and trunk

Reviewed by: Tom Ware - reviewed user-submitted fix

Tested with JPA LRG
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:15:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:32:54 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink