Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4361128
Votes 1
Synopsis heavyweight JPopupMenu causes low-level mouse movement exception
Category java:classes_swing
Reported Against 1.3
Release Fixed
State 11-Closed, duplicate of 4280243, bug
Priority: 4-Low
Related Bugs 4280243
Submit Date 09-AUG-2000
Description




java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


We use JPopupMenu to show up a scrolled list as it is well-known from JComboBox.
If the popup does not fit into the application frame (and therefore is created
as a heavy-weight WindowPopup), there occur low-level exceptions when moving the
mouse over the menu. The problem turned out to occur only the *SECOND* time, the
popup is displayed, so it may be related to DefaultPopupFactory's recycling
magic.
A similar effect has been reported much earlier with Bug ID 4142486. However,
the problems don't seem to be related. Se the following stack trace for details:

Exception occurred during event dispatching:
java.lang.NullPointerException: null pData
	at sun.awt.windows.WInputMethod.handleNativeIMEEvent(Native Method)
	at sun.awt.windows.WInputMethod.dispatchEvent(WInputMethod.java:275)
	at sun.awt. customer .InputContext.dispatchEvent(InputContext.java:202)
	at
sun.awt. customer .InputMethodContext.dispatchEvent(InputMethodContext.java:177)
	at java.awt.Component.dispatchEventImpl(Component.java:2529)
	at java.awt.Container.dispatchEventImpl(Container.java:1213)
	at java.awt.Component.dispatchEvent(Component.java:2499)
	at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
	at
java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:2318)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2189)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
	at java.awt.Container.dispatchEventImpl(Container.java:1200)
	at java.awt.Window.dispatchEventImpl(Window.java:912)
	at java.awt.Component.dispatchEvent(Component.java:2499)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
	at
java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

Analyzing the code of DefaultPopupFactory, we found a dubious detail in function
createHeavyWeightPopup() which may cause problems. There is an assignment made
to variable popup which refers to a *member* in createHeavyWeightPopup() while
it is declared as a local variable in createLightWeightPopup() and
createMediumWeightPopup(). This will probably mess up the class' logic. However,
it looks like this in JDK 1.2 and 1.2.2 too, which don't cause us any problems.
(Review ID: 108106) 
======================================================================
Work Around




We installed an alternative PopupFactory which holds an *EXACT* copy of
DefaultPopupFactory's source code. The class looks like this:

----------------------------------

package javax.swing;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.accessibility.*;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;

public class AltPopupFactory implements PopupFactory {
    private AltPopupFactory() {}
    private static AltPopupFactory instance;
    public static void install() {
        if (instance == null) {
            instance = new AltPopupFactory();
            JPopupMenu.setPopupFactory(instance);
        }
    }

    // Copy of DefaultPopupFactory's class body
    // ...

} // AltPopupFactory

-------------------------------------

This class must be put in a JAR file which is *prepended* to the bootclasspath.
Otherwise it as no access to Swing's base classes.
======================================================================
Evaluation
Can't seem to reproduce the problem since a test case was not submitted. However, the bug report was quite detailed.

As part of a fix to a memory leak in ToolTipManager (4352535), the create...() methods in DefaultPopupFactory were cleaned up. In fact, for createHeavyWeightPopup(), the 'popup' becomes a local variable and is initialized to null. This seems to address the submitter's analysis.

I can't verify this as fixed unless I have a reproducible test case. 
  xxxxx@xxxxx   2000-08-25

Closed as a duplicate of #4280243, which is fixed in the next feature release.
  xxxxx@xxxxx   2000-12-08
Comments
  
  Include a link with my name & email   

Submitted On 28-AUG-2000
shaung_liu
The way to reproduce this bug is having a JPopupMenu that 
is too large to fit into the parent frame, and contains 3 
or more JMenuItems plus a submenu with one or more 
JMenuItems.  Also, you must first select a JMenuItem that 
is not part of the submenu.  The next time the popup window 
is brought up in an area where it extends past the parent 
frame, the "null pData" exception will occur.  I can 
provide a sample app. demostrating this if necessary.


Submitted On 11-OCT-2000
jcgagne
Here is a sample app. Select the menu item "action 4" with a mouse-click (not
 a mouse-released). Then try to highlight the menu item "submenu". You should get the exception described 
above.


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JMenuBugTest extends JFrame {
	JButton btnDisable = new JButton();
	JMenuBar menuBar = new JMenuBar();
	JPopupMenu popup;

	public static void main(String[] args) {
		JMenuBugTest test = new JMenuBugTest();
		test.pack();
		test.setVisible(true);
	}

	public JMenuBugTest() {
		JMenu subMenu = new JMenu("submenu");
		subMenu.add(new MyAction("action 6"));
		subMenu.add(new MyAction("action 7"));
		subMenu.add(new MyAction("action 8"));

		JMenu menu = new JMenu(new MyAction("Fichier"));
		menu.add(new MyAction("action 1"));
		menu.add(new MyAction("action 2 with text too long to fit in a small window"));
		menu.add(subMenu);
		menu.add(new MyAction("action 4"));
		menu.add(new MyAction("action 5"));

		menuBar.add(menu);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setJMenuBar(menuBar);
	}


	public void dispose() {
		super.dispose();
		System.exit(0);
	}
}

class MyAction extends AbstractAction {
	MyAction(String aName) {
		super(aName);
	}

	public void actionPerformed(ActionEvent evt) {
		System.out.println(getValue(Action.NAME));
	}
}




PLEASE NOTE: JDK6 is formerly known as Project Mustang