JDK-6521706 : A switch operator in JFrame.processWindowEvent() should be rewritten
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-02-06
  • Updated: 2015-01-21
  • Resolved: 2014-08-06
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
8u40Fixed 9 b28Fixed
Description
-
JFrame.processWindowEvent() contains the following 'switch' operator:

if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    switch(defaultCloseOperation) {
      case HIDE_ON_CLOSE:
         setVisible(false);
         break;
      case DISPOSE_ON_CLOSE:
         dispose();
         break;
      case DO_NOTHING_ON_CLOSE:
         default:
         break;
      case EXIT_ON_CLOSE:
          // This needs to match the checkExit call in
          // setDefaultCloseOperation
         System.exit(0);
         break;
    }
}

Notice that the code is intricate. The 'default:' label is not the last one, but it is just after 'DO_NOTHING_ON_CLOSE:' label. Despite the code works properly, it should be rewritten in the following way:

if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    switch(defaultCloseOperation) {
      case HIDE_ON_CLOSE:
         setVisible(false);
         break;
      case DISPOSE_ON_CLOSE:
         dispose();
         break;
      case DO_NOTHING_ON_CLOSE:
         break;
      case EXIT_ON_CLOSE:
          // This needs to match the checkExit call in
          // setDefaultCloseOperation
         System.exit(0);
         break;
      default:
         break;
    }
}

Comments
EVALUATION See the description.
26-06-2007