JDK-6470361 : Swing's Threading Policy example does not compile
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-09-13
  • Updated: 2015-09-29
  • Resolved: 2014-12-16
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.
JDK 8 JDK 9
8u60Fixed 9 b45Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b98)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b98, mixed mode)

A DESCRIPTION OF THE PROBLEM :
The first example given on the Swing package documentation under the heading "Swing's Threading Policy" does not compile. A constructor is called with an argument String[], but no such constructor exists. Both examples are missing the import of javax.swing.SwingUtilities.

In my opinion the examples would be clearer if they did not attempt to deal with command line arguments or constructing other objects (MyApp). Also the access modifiers are overly public and java.awt.EventQueue.invokeLater is preferrable to the obsolete version in the SwingUtilities dumping ground. So a clearer, correct example would be:

class MyApp {
    private static void show() {
        // Show the UI.
    }

    public static void main(final String[] args) {
        // Schedule a job for the AWT event-dispatching thread:
        // creating and showing this application's GUI.
        java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    show();
                }
        });
    }
}



REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION The examples are not complete code, just rought guidelines. Will revisit this once app framework (jsr 296) goes in, and changes the recommendations.
14-09-2006