-
Bug
-
Resolution: Fixed
-
P1
-
1.1.3
-
1.1.5
-
sparc
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2016075 | 1.2.0 | Xianfa Deng | P1 | Resolved | Fixed | 1.2 |
Create a Choice component with 20 items. Use Choice.getItem(int) to get each item and store it in a Vector. Then use Choice.removeAll() to remove all items from the Choice. Then re-add the original 20 items from the Vector, and add one more item via Choice.addItem(). The last addItem() causes a core dump.
Below is a java application that reproduces the problem. Click on the add item button and the application will core dump.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class testChoice extends java.applet.Applet implements
ActionListener,
ItemListener {
Frame frame;
Choice choice;
Button addItemBtn;
public static void main(String args[]) {
Frame f = new Frame("Choice test");
testChoice clnt = new testChoice();
clnt.init();
clnt.start();
f.add("Center", clnt);
f.setSize(500, 300);
f.pack();
f.show();
}
public void init() {
// text to send and send button
setLayout(new GridLayout(2,2,1,1));
add(choice = new Choice());
for ( int i = 0; i < 20; i++ )
choice.addItem("test");
add(new Label(""));
choice.addItemListener(this);
add(new Label(""));
addItemBtn = new Button("Add Item");
add(addItemBtn);
addItemBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == choice) {
} else if (source == addItemBtn) {
Vector v = new Vector();
int numItems = choice.countItems();
for ( int i = 0; i < numItems; i++ )
v.addElement(choice.getItem(i));
choice.removeAll();
for ( int i = 0; i < numItems; i++ )
{
String s = (String)v.elementAt(i);
choice.addItem(s);
}
choice.addItem("New Item");
}
}
public void itemStateChanged(ItemEvent e) {
}
private Frame getFrame() {
if (frame == null) {
Container parent = (Container)this;
while(parent != null && ! (parent instanceof Frame)) {
parent = (Container)parent.getParent();
}
frame = (Frame) parent;
}
return (frame);
}
}
Below is a java application that reproduces the problem. Click on the add item button and the application will core dump.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class testChoice extends java.applet.Applet implements
ActionListener,
ItemListener {
Frame frame;
Choice choice;
Button addItemBtn;
public static void main(String args[]) {
Frame f = new Frame("Choice test");
testChoice clnt = new testChoice();
clnt.init();
clnt.start();
f.add("Center", clnt);
f.setSize(500, 300);
f.pack();
f.show();
}
public void init() {
// text to send and send button
setLayout(new GridLayout(2,2,1,1));
add(choice = new Choice());
for ( int i = 0; i < 20; i++ )
choice.addItem("test");
add(new Label(""));
choice.addItemListener(this);
add(new Label(""));
addItemBtn = new Button("Add Item");
add(addItemBtn);
addItemBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == choice) {
} else if (source == addItemBtn) {
Vector v = new Vector();
int numItems = choice.countItems();
for ( int i = 0; i < numItems; i++ )
v.addElement(choice.getItem(i));
choice.removeAll();
for ( int i = 0; i < numItems; i++ )
{
String s = (String)v.elementAt(i);
choice.addItem(s);
}
choice.addItem("New Item");
}
}
public void itemStateChanged(ItemEvent e) {
}
private Frame getFrame() {
if (frame == null) {
Container parent = (Container)this;
while(parent != null && ! (parent instanceof Frame)) {
parent = (Container)parent.getParent();
}
frame = (Frame) parent;
}
return (frame);
}
}
- backported by
-
JDK-2016075 Choice.removeAll() followed by Choice.addItem dumps core in some situtations
-
- Resolved
-