Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6521706

A switch operator in JFrame.processWindowEvent() should be rewritten

    XMLWordPrintable

Details

    • b28
    • generic
    • generic

    Backports

      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;
            }
        }

        Attachments

          Issue Links

            Activity

              People

                serb Sergey Bylokhov
                mlapshin Mikhail Lapshin (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: