United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4987087 : Frame.setExtendedState(int state) may work incorrect with misleading WM's

Details
Type:
Bug
Submit Date:
2004-02-02
Status:
Closed
Updated Date:
2004-04-29
Project Name:
JDK
Resolved Date:
2004-02-27
Component:
client-libs
OS:
solaris_2.6
Sub-Component:
java.awt
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
1.4.2_05 (05)

Related Reports
Backport:
Relates:

Sub Tasks

Description
Name: acR10002			Date: 02/02/2004



Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
java.awt.Frame:
...
public void setExtendedState(int state)

Sets the state of this frame. The state is represented as a bitwise mask. 
        NORMAL Indicates that no state bits are set. 
        ICONIFIED 
        MAXIMIZED_HORIZ 
        MAXIMIZED_VERT 
        MAXIMIZED_BOTH Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT. 

Note that if the state is not supported on a given platform, nothing will 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
happen. The application may determine if a specific state is available via 
^^^^^^
the java.awt.Toolkit#isFrameStateSupported(int state) method.

...
---------- end-of-excerpt ---------------

Problem description
===================

The problem was found during running the JCK interactive test
api/java/awt/interactive/FrameState/FrameStateTests with metacity WM.
The metacity WM reports that it can't handle single direction maximization, 
like MAXIMIZED_HORIZ or MAXIMIZED_VERT states. However, if asked to do
maximization along with a single direction, it does maximization in both 
directions resulting into the MAXIMIZED_BOTH frame. 

Currently, the JDK code doesn't handle such misleading WM behavior, 
just forwarding the setExtendedState() call to the underlying platform 
(in this case - metacity WM). This makes the JDK inconsistent with
J2SE API spec when run against metacity WM. According to the spec,
no size change should happen to Frame in case certain state is not 
supported.

Please find below the excerpt from licensee question:

>>With the code change, we correctly now identify that we are using the
>>Metacity wm.  The JCK test first questions the window manager to
>>establish whether it can maximise in the horizontal and vertical
>>directions.  The code now correctly returns false for this as Metacity
>>cannot do single direction maximisation.  However, the JCK test then
>>attempts to maximise in single directions but expects the result of the
>>window to remain unchanged.  This is because the Metacity says it cannot
>>do single direction.  But, rather than remain unchanged, Metacity will
>>maximise in both directions if given a single direction maximise
>>command.   

The JDK code could workaround misleading WM's and just don't forward
calls to WM in case WM reports it doesn't support a feature.


======================================================================

                                    

Comments
SUGGESTED FIX

Name: ynR10250			Date: 02/11/2004


*** /awt/yan/child1/webrev.4987087/src/share/classes/java/awt/Frame.java-       Thu Feb  5 13:14:21 2004
--- /awt/yan/child1/webrev.4987087/src/share/classes/java/awt/Frame.java        Thu Feb  5 13:14:21 2004

*** 687,703 ****
       * @see     #getExtendedState
       * @see     java.awt.Toolkit#isFrameStateSupported(int)
       * @since   1.4
       */
      public synchronized void setExtendedState(int state) {
          this.state = state;
          FramePeer peer = (FramePeer)this.peer;
          if (peer != null) {
              peer.setState(state);
          }
      }
! 
  
      /**
       * Gets the state of this frame (obsolete).
       * <p>
       * In older versions of JDK a frame state could only be NORMAL or
--- 687,721 ----
       * @see     #getExtendedState
       * @see     java.awt.Toolkit#isFrameStateSupported(int)
       * @since   1.4
       */
      public synchronized void setExtendedState(int state) {
+         if ( !isFrameStateSupported( state ) ) {
+             return;
+         }    
          this.state = state;
          FramePeer peer = (FramePeer)this.peer;
          if (peer != null) {
              peer.setState(state);
          }
      }
!     private boolean isFrameStateSupported(int state) {
!         if( !getToolkit().isFrameStateSupported( state ) ) {
!             // * Toolkit.isFrameStateSupported returns always false 
!             // on compound state even if all parts are supported;
!             // * if part of state is not supported, state is not supported;
!             // * MAXIMIZED_BOTH is not a compound state.
!             if( ((state & ICONIFIED) != 0) &&
!                 !getToolkit().isFrameStateSupported( ICONIFIED )) {
!                 return false;
!             }else {
!                 state &= ~ICONIFIED;
!             }
!             return getToolkit().isFrameStateSupported( state );
!         }    
!         return true;
!     }
  
      /**
       * Gets the state of this frame (obsolete).
       * <p>
       * In older versions of JDK a frame state could only be NORMAL or

###@###.### []


======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_05
generic
tiger-beta2

FIXED IN:
1.4.2_05
tiger-beta2

INTEGRATED IN:
1.4.2_05
tiger-b41
tiger-beta2

VERIFIED IN:
1.4.2_05


                                     
2004-08-24
EVALUATION

commit this to 1.4.2_05
###@###.### 2004-02-05

Name: ynR10250			Date: 02/11/2004

as of now, Toolkit.isFrameStateSupported() returns quite correct 
 results, if properly applied. We should check for these results 
 somewhere in java.awt.Frame.   
###@###.###

======================================================================

Fix verified for build 1.4.2_05-ea-b01
###@###.### 2004-04-29
###@###.### 2004-04-29
                                     
2004-08-24



Hardware and Software, Engineered to Work Together