United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4401222 JPopupMenu.setVisible(true) throws NullPointerException in headless mode
JDK-4401222 : JPopupMenu.setVisible(true) throws NullPointerException in headless mode

Details
Type:
Bug
Submit Date:
2001-01-02
Status:
Closed
Updated Date:
2001-07-12
Project Name:
JDK
Resolved Date:
2001-06-22
Component:
client-libs
OS:
solaris_8,solaris_7,linux
Sub-Component:
javax.swing
CPU:
x86,sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.0 (beta2)

Related Reports
Duplicate:
Duplicate:

Sub Tasks

Description
With this code	javax.swing.JPopupMenu lw = new javax.swing.JPopupMenu();
	lw.setVisible(true);

I get the following:

  !!  FAIL: javax.swing.JPopupMenu: do_setVisible_2 status=fail with exception=java.lang.NullPointerException
java.lang.NullPointerException
        at javax.swing.JPopupMenu.getPopup(JPopupMenu.java:733)
        at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:683)
        at javax_swing_JPopupMenu.do_setVisible_2(javax_swing_JPopupMenu.java:78)
        at javax_swing_JPopupMenu.run(javax_swing_JPopupMenu.java:3510)
        at java.lang.Thread.run(Thread.java:579)

Nowhere is Component.setVisible nor JPopupMenu.setVisible documented
to throw any exceptions.

Solaris 8 (sparc), JDK 1.4 build 46

--- begin - test.java-----

import javax.swing.JPopupMenu;

public class test {
	public static void main(String[] args) {
		JPopupMenu menu = new JPopupMenu();
		menu.setVisible(true);
	}
}
--- end - test.java ----

Execute in headless mode:

% java -Djava.awt.headless=true test
mark.davidson@Eng 2001-01-19

                                    

Comments
SUGGESTED FIX



Name: pzR10082			Date: 05/17/2001


The solution could be just to add a check for null to
the JPopupMenu.setVisible() method. Other Swing components
seem not to have this problem: JPopupMenu just has a very
special setVisible() method.

*** /tmp/geta1237	Thu May 17 16:09:09 2001
--- JPopupMenu.java	Thu May 17 15:41:27 2001
***************
*** 747,753 ****
                                            desiredLocationY);
  
          popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
!         newPopup.show();
          return newPopup;
      }
  
--- 747,755 ----
                                            desiredLocationY);
  
          popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
!         if (newPopup != null) {
!             newPopup.show();
!         }
          return newPopup;
      }
  

###@###.### 2001-05-17

======================================================================
                                     
2001-05-17
EVALUATION

I'm able to reproduce this on 1.4.b48.
mark.davidson@Eng 2001-01-19

As an initial fix, I've implemented checks for GraphicsEnvironment.isHeadless() in along the execution path. That only suceeds in pushing the encountered exception to other parts of the API (like in SwingUtilities.convertScreenLocationToParent()).

The meta question to ask is: does it make sense to call JPopupMenu.setVisible(true) in a headless environment? If so then what should happen?

mark.davidson@Eng 2001-03-19

Name: pzR10082			Date: 05/17/2001


It's hard to say what the submitted code is intended for, however,
there should be no NPE thrown anyway.

###@###.### 2001-05-17

======================================================================
                                     
2001-05-17
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
merlin-beta2

FIXED IN:
merlin-beta2

INTEGRATED IN:
merlin-beta2

VERIFIED IN:
merlin-beta2


                                     
2004-08-24



Hardware and Software, Engineered to Work Together