JDK-4401222 : JPopupMenu.setVisible(true) throws NullPointerException in headless mode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris_7,solaris_8
  • CPU: x86,sparc
  • Submitted: 2001-01-02
  • Updated: 2001-07-12
  • Resolved: 2001-06-22
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.
Other
1.4.0 beta2Fixed
Related Reports
Duplicate :  
Duplicate :  
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta2 FIXED IN: merlin-beta2 INTEGRATED IN: merlin-beta2 VERIFIED IN: merlin-beta2
24-08-2004

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 ======================================================================
17-05-2001

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 ======================================================================
17-05-2001