|
Quick Lists
|
|
Bug ID:
|
4280243
|
|
Votes
|
33
|
|
Synopsis
|
Kestrel I, jMenu app causes null pointer exceptions
|
|
Category
|
java:classes_awt_im
|
|
Reported Against
|
1.1
, 1.3
, kestrel
, 1.3.1-pr3
, kestrel-rc1
, kestrel-rc2
, kestrel-rc3
, kestrel-beta
|
|
Release Fixed
|
1.3.0_02,
1.3.1(ladybird) (Bug ID:2029568)
, 1.4(merlin-beta) (Bug ID:2029569)
|
|
State
|
10-Fix Delivered,
Verified,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
4281812
,
4298592
,
4309284
,
4329142
,
4356333
,
4361128
,
4399488
|
|
Submit Date
|
12-OCT-1999
|
|
Description
|
The following app causes null pointer exceptions. Run the app on any platform.
1. Invoke the application, do not resize the window
2. open the rightmost menu such that it extends outside the right side of the frame
3. pull right in the first item in the rightmost menu
4. click on the next pullright (an empty menu)
5. open the second menu fron the right and click in the firse menu item
6. open the first menu from the right and then open the first pullright
7. move the mouse cursor back and forth from the first menu to the pullright
You should see a null pointer stack trace. You might have to play with the
above instructions a bit.
import java.awt.*
import java.awt.event.*
import javax.swing.*
public class jMenu extends JApplet
{
public void init()
{
JFrame frame = new JFrame("\u0645\u062b\u0627\u0644")
frame.setJMenuBar(new jMenuX())
frame.pack()
frame.setVisible(true)
frame.setSize(300,300)
}
public static void main(String[] argv)
{
JFrame frame = new JFrame("\u0645\u062b\u0627\u0644")
frame.setJMenuBar(new jMenuX())
frame.pack()
frame.setVisible(true)
frame.setSize(300,300)
}
}
class jMenuX extends JMenuBar implements ActionListener
{
String[] fileItems = new String[] { "\u062c\u062f\u064a\u062f\u0020\u05d7\u05d3\u05e9", "\u0641\u062a\u062d\u0020\u0645\u0644\u0641", "\u062d\u0641\u0638\u0020", "\u05d9\u05e6\u05d9\u05d0\u05d4\u0020\u062e\u0631\u0648\u062c" } String[] editItems = new String[] { "\u05d4\u05e2\u05ea\u05e7\u0020\u0625\u0646\u0633\u062e", "\u05d7\u05ea\u05d5\u05da\u0020\u0625\u0642\u0637\u0639", "\u05ea\u05d5\u05e1\u05d9\u05e3\u0020\u0623\u0636\u0641", "\u0623\u0644\u0635\u0642\u0020\u05ea\u05e2\u05e1\u05d4" }
char[] fileShortcuts = { 'a','z','q','w' }
char[] editShortcuts = { 'x','c','v','k' }
public jMenuX() {
JMenu fileMenu = new JMenu("\u0645\u0644\u0641\u0020\u05e7\u05d5\u05d1\u05e5") JMenu editMenu = new JMenu("\u05d0\u05e4\u05e9\u05e8\u05d9\u05d5\u05ea\u0020\u062e\u064a\u0627\u0631\u0627\u062a") JMenu otherMenu = new JMenu("\u05d0\u05d7\u05e8\u0020\u0627\u062e\u0631")
JMenu subMenu = new JMenu("\u05ea\u05e4\u05e8\u05d9\u05d8\u0020\u0642\u0627\u0626\u0645\u0629")
JMenu subMenu2 = new JMenu("\u05ea\u05e4\u05e8\u05d9\u05d8\u0020\u05d7\u05d3\u05e9\u0020\u0642\u0627\u0626\u0645\u0629\u0020\u062c\u062f\u064a\u062f\u0629")
fileMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
editMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
subMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
subMenu2.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
for (int i=0 i < fileItems.length i++)
{
JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i])
item.addActionListener(this)
fileMenu.add(item)
}
for (int i=0 i < editItems.length i++)
{
JMenuItem item = new JMenuItem(editItems[i])
item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i],
java.awt.Event.CTRL_MASK, false))
item.addActionListener(this)
editMenu.add(item)
}
editMenu.insertSeparator(1)
JMenuItem item
subMenu2.add(item = new JMenuItem(""))
item.addActionListener(this)
subMenu.add(item = new JMenuItem(""))
item.addActionListener(this)
subMenu.add(subMenu2)
otherMenu.add(subMenu)
otherMenu.add(item = new JCheckBoxMenuItem("\u0623\u0646\u0642\u0631\u0020\u05ea\u05dc\u05d7\u05e5"))
item.addActionListener(this)
otherMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
otherMenu.addSeparator()
ButtonGroup buttonGroup = new ButtonGroup()
otherMenu.add(item = new JRadioButtonMenuItem("\u0631\u0627\u062f\u064a\u0648\u0020\u05e8\u05d3\u05d9\u05d5"))
item.addActionListener(this)
buttonGroup.add(item)
otherMenu.add(item = new JRadioButtonMenuItem("\u0631\u0627\u062f\u064a\u0648\u0020\u05e8\u05d3\u05d9\u05d5"))
item.addActionListener(this)
item.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
buttonGroup.add(item)
otherMenu.addSeparator()
otherMenu.add(item = new JMenuItem("",
new ImageIcon("image.gif")))
item.addActionListener(this)
add(fileMenu)
add(editMenu)
add(otherMenu)
}
public void actionPerformed(ActionEvent event) {
System.out.println("Menu item [" + event.getActionCommand() +
"] was pressed.")
}
public static void main(String s[]) {
JFrame frame = new JFrame("Simple Menu Example")
frame.setJMenuBar(new jMenuX())
frame.pack()
frame.setVisible(true)
}
}
WorkAround:
======================================================================
java version "1.3.0rc2"
java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
Java HotSpot(TM) Client VM (build 1.3.0.rc-Y, mixed mode)
When nesting submenus, null pointer exceptions occur. Although the example
below nests 2 submenus, the error also occurs (though less reliably) with just
a single submenu. I believe this is the same error as bug 4280243, but as that
bug report was submitted on October 12, 1999 and has not yet been reviewed, I
am submitting it again, this time against 1.3.0rc2.
This is a very serious problem for building applications, and I would
appreciate any suggestions of workarounds (other than never nesting JMenus).
To trigger the null pointer exception, pull down the menu item "Menu Example",
click on "SubMenu 2", then go back to the menu bar and try to pull down
"Menu Example" again. This always triggers the error on my comptuer, but
some variation of this may be required.
This code is a simplified version of the code supplied in bug 4280243
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class jMenuX extends JMenuBar{
public jMenuX() {
JMenu otherMenu = new JMenu("Menu Example");
JMenu subMenu = new JMenu("SubMenu1");
JMenu subMenu2 = new JMenu("SubMenu2");
subMenu.add(subMenu2);
subMenu2.add(new JMenuItem("Item"));
otherMenu.add(subMenu);
add(otherMenu);
}
public static void main(String s[]) {
JFrame frame = new JFrame("Simple Menu Example");
frame.setJMenuBar(new jMenuX());
frame.pack();
frame.setVisible(true);
}
}
Here is the error message produced:
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:1
77)
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:231
8)
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:10
3)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
(Review ID: 103596)
======================================================================
java version "1.3.0rc3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)
I'm seeing this exception being thrown as I use jmenus that are used over a
pjpanel that is placed in a jframe. I cannot provide any test code as time does
not permit me to do so, and I have no real way of customer *how* to reproduce
this. Perhaps this exception might help:
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)
If I can be of any help (after someone has read this exception and may have
some ideas), feel free to ask.
(Review ID: 103978)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
Commit to fix in Merlin and Ladybird (menus throw NPE).
xxxxx@xxxxx 2000-04-24
xxxxx@xxxxx 2000-05-19
The test case can be minimized to:
import javax.swing.*;
public class jMenu {
public static void main(String[] argv) {
JFrame frame = new JFrame("null pData");
JMenu menu = new JMenu("Click me");
menu.add(new JMenu("Now click ME!")); // NB: but not JMenuItem
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
frame.setJMenuBar(menuBar);
frame.pack();
frame.setVisible(true);
}
}
This bug manifests when the pull down menu doesn't fit completely into
the frame's bounds and swing has to create a seaprate window for the
pull-down (pack() in the test case above ensures that frame is very
small).
This is the same problem as 4309284, "exception thrown when adding a
component for the second time". As submitter of 4309284 correctly
suggests - the problem is that WInputMethod caches a reference to
peer and that that reference becomes stale when peer is destroyed and
recreated.
In this bug cached peer reference becomes stale as the Window for the
menu is hidden (and its peer is destroyed) and shown again (with new
peer this time). WInputMethod have a cached regerence to the old peer
but that old peer is not connected (via pData) to the underlying
native window used to display the menu.
In 4309284 peer is destroyed and recreated during remove/add cycle
with exactly the same effect.
This bug and 4309284 are clear duplicates. I propose to recategorize
this bug against IM and let them decide which one they want to track.
======================================================================
|
|
Comments
|
Submitted On 08-JUN-2000
dkroy
I have the same kind of problem with SUb-Menus
Here are the details. KNOCK ! KNOCK ! Sun Support team.
I am developing a menu Applet and to some extent it works
fine except with the
sub menus. When the menu is displayed for the first time
everything works fine
even with the sub menus. The submenu navigation works only
once or sometime
twice and after that I get the above exception and the
submenu is NOT
ACCESSIBLE at all !
Here is the error message:
Exception occurred during event dispatching:
java.lang.NullPointerException: null pData
at sun.awt.windows.WInputMethod.handleNativeIMEEvent
(Native Method)
at sun.awt.windows.WInputMethod.dispatchEvent
(Unknown Source)
at sun.awt.im.InputContext.dispatchEvent(Unknown
Source)
at sun.awt.im.InputMethodContext.dispatchEvent
(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown
Source)
at java.awt.Container.dispatchEventImpl(Unknown
Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent
(Unknown Source)
at
java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown
Source)
at java.awt.LightweightDispatcher.processMouseEvent
(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent
(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown
Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEvent
(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown
Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here is the source code:
/********************************************************/
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.JPopupMenu;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.ButtonGroup;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.*;
/*
* This class adds popup menus to MenuDemo.
*/
public class PopupMenuDemo extends JApplet
implements ActionListener,
ItemListener {
JTextArea output;
JScrollPane scrollPane;
String newline = "\n";
JPopupMenu popup;
public PopupMenuDemo() {
try { jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
JMenuBar menuBar;
JMenu menu, submenu;
JMenuItem menuItem;
JRadioButtonMenuItem rbMenuItem;
JCheckBoxMenuItem cbMenuItem;
//Add regular components to the window, using the
default BorderLayout.
//Create the menu bar.
menuBar = new JMenuBar();
setJMenuBar(menuBar);
//Build the first menu.
menu = new JMenu("A Menu");
menu.setMnemonic(KeyEvent.VK_A);
menu.getAccessibleContext().setAccessibleDescription
(
"The only menu in this program that has
menu items");
menuBar.add(menu);
//a group of JMenuItems
menuItem = new JMenuItem("A text-only menu item",
KeyEvent.VK_T);
//menuItem.setMnemonic(KeyEvent.VK_T); //used
constructor instead
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));
menuItem.getAccessibleContext
().setAccessibleDescription(
"This doesn't really do anything");
menuItem.addActionListener(this);
menu.add(menuItem);
//a group of radio button menu items
menu.addSeparator();
ButtonGroup group = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem("A radio
but
Submitted On 21-JUN-2000
surpac
This bug is really serious. You can't create any viable applications based on JDK1.3 with this problem
present.
Submitted On 25-JUN-2000
kuhse
Related bug: 4298592
Submitted On 17-AUG-2000
tbweiss
Does anyone know the scheduled release of the fix for this
bug? It is blocking the release of our product with jdk
1.3. A timely response from Sun would be appreciated.
Submitted On 30-AUG-2000
yuk.ishida
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)
this is a Workaround
//add this code
someJMenuItem.enableInputMethods(false);
Submitted On 09-NOV-2000
dhunter21
How can this bug be closed and fixed when a fix hasn't been
implemented AND a viable work around has not been
presented? Are we not supose to use sub menues???
Submitted On 28-NOV-2000
DECOSTERM
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)
I have the same problem when I include a jMenuItem in a JPopupMenu. This exception occurs after click on the
JMenuItem, execute the action and then click on another JMenuItem.
I cannot product a new version of my application with the version of the JDK (My old version use JDK 1.2.2-w)
Submitted On 19-DEC-2000
andyhink
implemented the fix presented by yuk.ishida...set
enableInputMethods(false) for the Menu with subMenuItems
and this worked. Many thanks....
Submitted On 30-JAN-2001
jbellis
Thanks, ishida! enableInputMethods(false) works for us,
too.
Submitted On 16-FEB-2001
anhaddad
AHADDAD
Here is a method I used to implement the work around for a
multi level menu. Pass the Parent container (JPopupMenu in
my case) as a seed to the recursive method below:
private
void
fixInputMethodProblem
(
JComponent componentToFix
)
{
int iMax =
componentToFix.getComponentCount();
for( int i = 0; i < iMax; i++ )
{
Component comp =
componentToFix.getComponent( i );
if( comp instanceof JMenuItem )
{
comp.enableInputMethods(
false );
}
else
{
fixInputMethodProblem(
componentToFix );
}
}
}
Submitted On 01-MAR-2001
easdown
Yes, I'd like to see this fixed too. The workaround
provided by yuk.ishida works fine, but a real fix would be
great.
Submitted On 24-MAR-2001
AndersDahlberg
Thanks ishida!
Submitted On 04-SEP-2001
roytate
I added the following line, which forces "heavyweight" menus and my exceptions seem to have stopped!
// fix for JPopupMenu crash near JFrame borders
JPopupMenu.setDefaultLightWeightPopupEnabled( false );
Submitted On 07-SEP-2001
jay_killer69
bitch
Submitted On 05-OCT-2001
cheesus
This one compiles:
/***************************************************************************
* applies a workaround for bug 4280243 which causes a null pdata
* NullPointerException for menus with submenus
*
* @see http://developer.java.sun.com/developer/bugParade/bugs/4280243.html
**************************************************************************/
public static void fixJMenuItem (JComponent componentToFix)
{
int iMax = componentToFix.getComponentCount();
for( int i = 0; i < iMax; i++ )
{
Component comp = componentToFix.getComponent( i );
if (!(comp instanceof JComponent)) continue;
if( comp instanceof JMenuItem )
{
comp.enableInputMethods( false );
}
else
{
fixJMenuItem( (JComponent) comp );
}
}
}
Thanks, anhaddad! This was a nasty one!
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |