JDK-6718641 : Nimbus LF: java.util.ConcurrentModificationException, thread timing problem
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-06-24
  • Updated: 2011-02-16
  • Resolved: 2008-06-24
Related Reports
Duplicate :  
Description
C:\Documents and Settings\Administrator\Desktop>java -version
java version "1.6.0_10-beta"
Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
Java HotSpot(TM) Client VM (build 11.0-b12, mixed mode, sharing)


 The exception happens at start-up time when creating the Swing objects in different threads.
 As it's thread related it is not always reproducable but I have it at more than 9/10. Start the application several times then to see it.

 I use Win XP/sp2 with build 1.6.0_10-beta-b25

Start test case over and over again, it may take 10+ times before you see the exception, sooner on a multi-cpu system.

---------------------test case--------------------------------------------
import java.awt.*;
import javax.swing.*;

// javac TestNimbusThreading.java
// java -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel TestNimbusThreading
public class TestNimbusThreading {

    public TestNimbusThreading() {
        try {
            final JFrame mainFrame = new JFrame();
            final JPanel jpGrid = new JPanel(new GridLayout(5,5));
            final SwingObjectCreation[] tableCreation = new SwingObjectCreation[25];
            for (int i=0; i<tableCreation.length; i++) {
                tableCreation[i] = new SwingObjectCreation();
                tableCreation[i].start();
            }
            for (int i=0; i<tableCreation.length; i++) {
                tableCreation[i].join();
            }
            SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        for (int i=0; i<tableCreation.length; i++) {
                            jpGrid.add(new JScrollPane(tableCreation[i].getTable()));
                        }
                        mainFrame.getContentPane().add(jpGrid);
                        mainFrame.pack();
                        mainFrame.setVisible(true);
                        mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                    }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        new TestNimbusThreading();
    }
    
    public static class SwingObjectCreation extends Thread {

        private JTable table;
        
        public void run() {
            table = new JTable(3,2);
        }
        
        public JTable getTable() {
            return table;
        }
    }
}

---------------------------end test case -------------------------------

Comments
EVALUATION This is not expected to work since about 2003. The rules for threading in Swing were changed to say that all object contruction must be done on the event dispatching thread (EDT). Prior to then object contruction was allowed before the top level(Frame) was realised, but that is no longer the case. Almost all code in Swing assumes it is running on the EDT in a single threaded model, Nimbus LAF is no different. There is documented in the Swing Tutorial at http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html .Also the history is exmplained at http://bitguru.wordpress.com/2007/03/21/will-the-real-swing-single-threading-rule-please-stand-up/ In the test case this means all the contnets of TestNimbusThreading need to be inside a SwingUtilities.invokeLater.. *** (#1 of 1): [ UNSAVED ] ###@###.###
24-06-2008