JDK-6786238 : api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u12
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-12-17
  • Updated: 2012-03-22
  • Resolved: 2009-01-29
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 6 JDK 7
6u12 b03Fixed 7Fixed
Related Reports
Relates :  
Description
JCK            : JCK runtime 6b b24
J2SE           : FAIL - since jdk 6u12 build 02 (Passes with b01)
Platform[s]    : FAIL - Any (Found on linux and windows vista)
Java options   : FAIL - Any

4 testcases of the test api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
This testcases are DefaultDesktopManager2012 DefaultDesktopManager2013
DefaultDesktopManager2014 DefaultDesktopManager2015

Please, see *.jtr file in comments.

Steps to reproduce:
1. Install JCK (for ex. to /export/JCK/JCK-runtime-6b/)
2. Install JDK (for ex. to /export/jdk/jdk1.6.0_12)
3. Run the simple script:
#!/bin/bash -v

export JAVA=/export/jdk/jdk1.6.0_12/bin/java
export CLASSPATH="/export/JCK/JCK-runtime-6b/classes"

OPTS=""
TEST=javasoft.sqe.tests.api.javax.swing.DefaultDesktopManager.xxxFrameTests

$JAVA -version
$JAVA  $TEST

Test source could be reduced to
import java.awt.*;
import javax.swing.*;

public class test {
    public static void main(String argv[]) {
        JComponent internalFrame = new JInternalFrame();
        JDesktopPane p = new JDesktopPane();

        p.add(internalFrame);

        DefaultDesktopManager c = new DefaultDesktopManager();
        p.setDesktopManager(c);

	// Uncomment one of the following lines to see NPE
        //c.beginResizingFrame( internalFrame, 10);
        //c.beginDraggingFrame( internalFrame);

        System.out.println("OK");
    }
}

When you execute this class exceptions would be:

Exception in thread "main" java.lang.NullPointerException: The window argument should not be null.
        at com.sun.awt.AWTUtilities.isWindowOpaque(AWTUtilities.java:410)
        at javax.swing.DefaultDesktopManager.setupDragMode(DefaultDesktopManager.java:303)
        at javax.swing.DefaultDesktopManager.beginResizingFrame(DefaultDesktopManager.java:375)
        at test.main(test.java:14)

Exception in thread "main" java.lang.NullPointerException: The window argument should not be null.
        at com.sun.awt.AWTUtilities.isWindowOpaque(AWTUtilities.java:410)
        at javax.swing.DefaultDesktopManager.setupDragMode(DefaultDesktopManager.java:303)
        at javax.swing.DefaultDesktopManager.beginDraggingFrame(DefaultDesktopManager.java:277)
        at test.main(test.java:19)

Problematic function is setupDragMode since SwingUtilities.getWindowAncestor(f) according to specification could return NULL and this is not handled.

public static Window getWindowAncestor(Component c)
Returns:
  the first Window ancestor of c, or null if component is not contained inside a window

    private void setupDragMode(JComponent f) {
        JDesktopPane p = getDesktopPane(f);
        Container parent = f.getParent();
        dragMode = DEFAULT_DRAG_MODE;
        if (p != null) {
            String mode = (String)p.getClientProperty("JDesktopPane.dragMode");
            if (!AWTUtilities.isWindowOpaque(SwingUtilities.getWindowAncestor(f))) {  // exception here
                dragMode = DEFAULT_DRAG_MODE;
            } else if (mode != null && mode.equals("outline")) {
                dragMode = OUTLINE_DRAG_MODE;
            } else if (mode != null && mode.equals("faster")
                    && f instanceof JInternalFrame
                    && ((JInternalFrame)f).isOpaque() &&
                       (parent == null || parent.isOpaque())) {
                dragMode = FASTER_DRAG_MODE;
            } else {
                if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
                    dragMode = OUTLINE_DRAG_MODE;
                } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
                        && f instanceof JInternalFrame
                        && ((JInternalFrame)f).isOpaque()) {
                    dragMode = FASTER_DRAG_MODE;
                } else {
                    dragMode = DEFAULT_DRAG_MODE;
                }
            }
        }
    }

It may be possible that this regression is introduced by fix for CR 6726866

Comments
EVALUATION The description gives all the informaiton about the problem and the reason why it happens The provided test illustrates a highly artificial situation when beginResizingFrame() is called manually just for testing purposes The beginResizingFrame() is called when the user draggs an internal frame with the mouse which impies the fact that it is visible However in the provided test case the JDesktopPane is not added to a visible JFrame Swing is not ready to this situation a simple "new JFrame().add(p);" added before the c.beginResizingFrame() eliminates the problem in the test
17-12-2008