JDK-6636331 : ConcurrentModificationException in AppContext code
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u10,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_vista
  • CPU: generic,x86
  • Submitted: 2007-12-01
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u23Fixed 6u10Fixed 7 b25Fixed
Related Reports
Duplicate :  
Description
the following problem has been reported by ###@###.###

I happened to find this exception in one of our nightly testing logs. Is this a known issue? It looks like a lack of synchronization in AppContext.getAppContexts().

Exception in thread "Thread-2" java.lang.ExceptionInInitializerError
    at com.sun.deploy.util.DeployUIManager.setLookAndFeel(Unknown Source)
    at sun.plugin.util.PluginSysUtil$1.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.util.ConcurrentModificationException
    at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(Unknown Source)
    at java.util.IdentityHashMap$ValueIterator.next(Unknown Source)
    at java.util.AbstractCollection.addAll(Unknown Source)
    at java.util.HashSet.<init>(Unknown Source)
    at sun.awt.AppContext.getAppContexts(Unknown Source)
    at java.awt.Toolkit$DesktopPropertyChangeSupport.firePropertyChange(Unknown Source)
    at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
    at java.awt.Toolkit.setDesktopProperty(Unknown Source)
    at sun.awt.windows.WToolkit.updateProperties(Unknown Source)
    at sun.awt.windows.WToolkit.lazilyInitWProps(Unknown Source)
    at sun.awt.windows.WToolkit.lazilyLoadDesktopProperty(Unknown Source)
    at java.awt.Toolkit.getDesktopProperty(Unknown Source)
    at javax.swing.UIManager.<clinit>(Unknown Source)
    ... 3 more

Comments
SUGGESTED FIX --- a/src/share/classes/sun/awt/AppContext.java Sat Dec 15 08:25:38 2007 +0300 +++ b/src/share/classes/sun/awt/AppContext.java Sat Dec 15 08:26:12 2007 +0300 @@ -146,7 +146,9 @@ public final class AppContext { * Returns a set containing all <code>AppContext</code>s. */ public static Set<AppContext> getAppContexts() { - return new HashSet<AppContext>(threadGroup2appContext.values()); + synchronized (threadGroup2appContext) { + return new HashSet<AppContext>(threadGroup2appContext.values()); + } } /* The main "system" AppContext, used by everything not otherwise
13-03-2008

EVALUATION actually there is very simple fix. a map Collections.synchronizedMap() returns uses this for synchronization (it is part of contract of this method) So we just need to use the same syncronization in our code public static Set<AppContext> getAppContexts() { synchronized (threadGroup2appContext) { return new HashSet<AppContext>(threadGroup2appContext.values()); } }
01-12-2007

EVALUATION Well, we can not just use clone() since threadGroup2appContext is a Map which doesn't have clone() method. Also we can not use IdentityHashMap as type for threadGroup2appContext since we need to have synchronized map, but Collections.synchronizedMap() returns just Map. It looks like to fix the problem we should create some special class which will provide Map interface (well not complete interface, just methods we need) and method clone().
01-12-2007

EVALUATION It looks like the problem is in AppContext.getAppContexts() public static Set<AppContext> getAppContexts() { return new HashSet<AppContext>(threadGroup2appContext.values()); } we should clone threadGroup2appContext before getting values. The problem was introduced by the fix for 6536220.
01-12-2007