I've found the following questionable behavior of the
MenuItem.setLabel method in case of bound arguments 'null' and ""
(empty string).
The javadoc for this method claims:
public void setLabel(String label)
Sets the label for this menu item to the specified label.
Parameters:
label - the new label, or null for no label.
Under Win32 calling setLabel(null) causes NPE in native code
(because of null checking in awt_MenuItem.cpp,
Java_sun_awt_windows_WMenuItemPeer__1setLabel, line 675
JNI_CHECK_NULL_RETURN(label, "null label").
Under Solaris, though, it just sets blank label for the menuitem
which is what it's supposed to do.
But under Solaris very strange things happen when calling setLabel("") -
it sets garbage as the label (actually, it somehow recalls the first
label which has been set for this menu item)
Under Win32 setting "" as a label just sets blank label which is ok.
Here is a small test which could help to examine the problem:
import java.awt.*;
import java.awt.event.*;
public class Test {
Frame frame = new Frame();
Menu menu = new Menu("Menu");
MenuItem mi = new MenuItem("Item");
MenuBar mb = new MenuBar();
Button button1 = new Button("set to null");
Button button2 = new Button("set to empty str");
Button button3 = new Button("set to 'stuff'");
public Test() {
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to null");
mi.setLabel(null);
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to empty");
mi.setLabel("");
}
});
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to 'stuff'");
mi.setLabel("stuff");
}
});
menu.add(mi);
mb.add(menu);
frame.add("North", button1);
frame.add("South", button2);
frame.add("Center", button3);
frame.setMenuBar(mb);
frame.pack();
frame.setVisible(true);
}
public static void main( String[] args ) {
new Test();
}
}
###@###.### 1999-06-30 ###@###.###
MenuItem.setLabel method in case of bound arguments 'null' and ""
(empty string).
The javadoc for this method claims:
public void setLabel(String label)
Sets the label for this menu item to the specified label.
Parameters:
label - the new label, or null for no label.
Under Win32 calling setLabel(null) causes NPE in native code
(because of null checking in awt_MenuItem.cpp,
Java_sun_awt_windows_WMenuItemPeer__1setLabel, line 675
JNI_CHECK_NULL_RETURN(label, "null label").
Under Solaris, though, it just sets blank label for the menuitem
which is what it's supposed to do.
But under Solaris very strange things happen when calling setLabel("") -
it sets garbage as the label (actually, it somehow recalls the first
label which has been set for this menu item)
Under Win32 setting "" as a label just sets blank label which is ok.
Here is a small test which could help to examine the problem:
import java.awt.*;
import java.awt.event.*;
public class Test {
Frame frame = new Frame();
Menu menu = new Menu("Menu");
MenuItem mi = new MenuItem("Item");
MenuBar mb = new MenuBar();
Button button1 = new Button("set to null");
Button button2 = new Button("set to empty str");
Button button3 = new Button("set to 'stuff'");
public Test() {
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to null");
mi.setLabel(null);
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to empty");
mi.setLabel("");
}
});
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.err.println("setting the label to 'stuff'");
mi.setLabel("stuff");
}
});
menu.add(mi);
mb.add(menu);
frame.add("North", button1);
frame.add("South", button2);
frame.add("Center", button3);
frame.setMenuBar(mb);
frame.pack();
frame.setVisible(true);
}
public static void main( String[] args ) {
new Test();
}
}
###@###.### 1999-06-30 ###@###.###