JDK-8073420 : JFrame.EXIT_ON_CLOSE can be removed in favour of WindowConstants.EXIT_ON_CLOSE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-02-18
  • Updated: 2017-05-17
  • Resolved: 2015-03-03
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 9
9 b56Fixed
Sub Tasks
JDK-8176291 :  
Description
  - In JDK 1.2 javax.swing.WindowConstants interface was added.
  - But unfortunately WindowConstants didn't contain EXIT_ON_CLOSE constant, later in jdk 1.3 this constant was added to the JFrame class, which implements WindowConstants.
  - Later it was realized that it should be added to the WindowConstants instead, and this was fixed in jdk 1.4

EXIT_ON_CLOSE fields are static constant variables (JLS 4.12.4). When source code references either field, a Java compiler is required to inline the field's value into the resulting class file (JLS 14.21).

This means that removing EXIT_ON_CLOSE from JFrame is binary compatible,
because no class file actually refers to the field in JFrame directly (JLS 13.4.9).

In addition, removing EXIT_ON_CLOSE from JFrame is source compatible,
because JFrame continues to have an EXIT_ON_CLOSE member (via
inheritance from WindowConstants) so code which refers to
JFrame.EXIT_ON_CLOSE will recompile.

 javax.swing.WindowConstants:
      /**
       * The exit application default window close operation. Attempting
       * to set this on Windows that support this, such as
       * <code>JFrame</code>, may throw a <code>SecurityException</code> based
       * on the <code>SecurityManager</code>.
       * It is recommended you only use this in an application.
       *
       * @since 1.4
       * @see JFrame#setDefaultCloseOperation
       */
      public static final int EXIT_ON_CLOSE = 3;

 javax.swing.JFrame implements WindowConstants,:
      /**
       * The exit application default window close operation. If a window
       * has this set as the close operation and is closed in an applet,
       * a <code>SecurityException</code> may be thrown.
       * It is recommended you only use this in an application.
       *
       * @since 1.3
       */
      public static final int EXIT_ON_CLOSE = 3;