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

[macosx] Error when using setDesktopManager on a JDesktopPane on MacOS X with Look and Feel Aqua

    XMLWordPrintable

Details

    • b08
    • generic
    • os_x

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X :
      Darwin Kernel Version 16.1.0: Thu Oct 13 21:26:57 PDT 2016; root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      When using
      desktop.setDesktopManager(new DefaultDesktopManager());
      with LookAndFeel com.apple.laf.AquaLookAndFeel,
      iconifying JInternalFrames causes crash.

      REGRESSION. Last worked in version 6u45

      ADDITIONAL REGRESSION INFORMATION:
      Don'l know if regression occurred with Java 7

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Taking the InternalFrameDemo source code :
      https://docs.oracle.com/javase/tutorial/uiswing/examples/components/InternalFrameDemoProject/src/components/InternalFrameDemo.java

      If you add
      desktop.setDesktopManager(new DefaultDesktopManager());
      in the Constructor,
      next time you'll try to iconify an internalframe, the problem will occur.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No crash expected

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at javax.swing.RepaintManager.getVolatileOffscreenBuffer(RepaintManager.java:1030)
      at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1489)
      at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
      at javax.swing.JComponent.paint(JComponent.java:1042)
      at javax.swing.JComponent.paintChildren(JComponent.java:889)
      at javax.swing.JComponent.paint(JComponent.java:1065)
      at com.apple.laf.AquaInternalFrameDockIconUI$ScaledImageLabel.updateIcon(AquaInternalFrameDockIconUI.java:193)
      at com.apple.laf.AquaInternalFrameDockIconUI$ScaledImageLabel.paint(AquaInternalFrameDockIconUI.java:204)
      at javax.swing.JComponent.paintChildren(JComponent.java:889)
      at javax.swing.JComponent.paint(JComponent.java:1065)
      at javax.swing.JComponent.paintChildren(JComponent.java:889)
      at javax.swing.JComponent.paint(JComponent.java:1065)
      at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
      at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
      at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
      at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
      at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
      at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
      at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
      at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
      at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
      at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
      at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
      at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:709)
      at java.awt.EventQueue$3.run(EventQueue.java:703)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
       *
       * Redistribution and use in source and binary forms, with or without
       * modification, are permitted provided that the following conditions
       * are met:
       *
       * - Redistributions of source code must retain the above copyright
       * notice, this list of conditions and the following disclaimer.
       *
       * - Redistributions in binary form must reproduce the above copyright
       * notice, this list of conditions and the following disclaimer in the
       * documentation and/or other materials provided with the distribution.
       *
       * - Neither the name of Oracle or the names of its
       * contributors may be used to endorse or promote products derived
       * from this software without specific prior written permission.
       *
       * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
       * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
       * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
       * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
       * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
       * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
       * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       */

      package components;

      import javax.swing.DefaultDesktopManager;
      import javax.swing.JInternalFrame;
      import javax.swing.JDesktopPane;
      import javax.swing.JMenu;
      import javax.swing.JMenuItem;
      import javax.swing.JMenuBar;
      import javax.swing.JFrame;
      import javax.swing.KeyStroke;

      import java.awt.event.*;
      import java.awt.*;

      /*
       * InternalFrameDemo.java requires:
       * MyInternalFrame.java
       */
      public class InternalFrameDemo extends JFrame
                                     implements ActionListener {

      JDesktopPane desktop;

          public InternalFrameDemo() {
              super("InternalFrameDemo");

              //Make the big window be indented 50 pixels from each edge
              //of the screen.
              int inset = 50;
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setBounds(inset, inset,
                        screenSize.width - inset*2,
                        screenSize.height - inset*2);

              //Set up the GUI.
              desktop = new JDesktopPane(); //a specialized layered pane
              
              ////////////////////////////////////////////////////
              // If you add this line, iconification will fail :
      desktop.setDesktopManager(new DefaultDesktopManager());
      ////////////////////////////////////////////////////

              createFrame(); //create first "window"
              setContentPane(desktop);
              setJMenuBar(createMenuBar());

              //Make dragging a little faster but perhaps uglier.
              desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
          }

          protected JMenuBar createMenuBar() {
              JMenuBar menuBar = new JMenuBar();

              //Set up the lone menu.
              JMenu menu = new JMenu("Document");
              menu.setMnemonic(KeyEvent.VK_D);
              menuBar.add(menu);

              //Set up the first menu item.
              JMenuItem menuItem = new JMenuItem("New");
              menuItem.setMnemonic(KeyEvent.VK_N);
              menuItem.setAccelerator(KeyStroke.getKeyStroke(
                      KeyEvent.VK_N, ActionEvent.ALT_MASK));
              menuItem.setActionCommand("new");
              menuItem.addActionListener(this);
              menu.add(menuItem);

              //Set up the second menu item.
              menuItem = new JMenuItem("Quit");
              menuItem.setMnemonic(KeyEvent.VK_Q);
              menuItem.setAccelerator(KeyStroke.getKeyStroke(
                      KeyEvent.VK_Q, ActionEvent.ALT_MASK));
              menuItem.setActionCommand("quit");
              menuItem.addActionListener(this);
              menu.add(menuItem);

              return menuBar;
          }

          //React to menu selections.
          public void actionPerformed(ActionEvent e) {
              if ("new".equals(e.getActionCommand())) { //new
                  createFrame();
              } else { //quit
                  quit();
              }
          }

          //Create a new internal frame.
          protected void createFrame() {
              MyInternalFrame frame = new MyInternalFrame();
              frame.setVisible(true); //necessary as of 1.3
              desktop.add(frame);
              try {
                  frame.setSelected(true);
              } catch (java.beans.PropertyVetoException e) {}
          }

          //Quit the application.
          protected void quit() {
              System.exit(0);
          }

          /**
           * Create the GUI and show it. For thread safety,
           * this method should be invoked from the
           * event-dispatching thread.
           */
          private static void createAndShowGUI() {
              //Make sure we have nice window decorations.
              JFrame.setDefaultLookAndFeelDecorated(true);

              //Create and set up the window.
              InternalFrameDemo frame = new InternalFrameDemo();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              //Display the window.
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      Attachments

        1. InternalFrameDemo.java
          6 kB
          Abhijit Roy
        2. MyInternalFrame.java
          2 kB
          Fairoz Matte

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: