Name: gm110360 Date: 10/04/2002
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION :
SunOS brooke 5.9 Generic_112233-01 sun4u sparc SUNW,Ultra-1
ADDITIONAL OPERATING SYSTEMS :
Linux gescher 2.4.19-PMC-SMP #3 SMP Mon Sep 9 22:33:11 CEST 2002 i686 unknown
A DESCRIPTION OF THE PROBLEM :
"Invalid" indices - that is, indices that I didn't add - are returned by getSelectedIndices() depending on the order setModel and addListSelectionListener are executed.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the program below - the output is 0|1, even though the only index that was selected is 0.
2. Comment out the first line with setModel; uncomment the second line with setModel, compile and run the program again - the output is 0|
EXPECTED VERSUS ACTUAL BEHAVIOR :
The output should be the same (preferably 0|) in both cases.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class Foo {
public static void main(String[] args) {
JFrame frame = new JFrame();
final DefaultListModel model = new DefaultListModel();
final JList list = new JList();
ListDataListener ldl = new ListDataListener() {
public void contentsChanged(ListDataEvent e) { }
public void intervalRemoved(ListDataEvent e) { }
public void intervalAdded(ListDataEvent e) {
if (model.getSize() != 0 && list.isSelectionEmpty()) {
list.setSelectedIndex(0);
}
}
};
list.setModel(model);
model.addListDataListener(ldl);
//list.setModel(model);
model.add(0, "thou");
int[] indices = list.getSelectedIndices();
for(int i = 0; i < indices.length; i++) {
System.out.print(indices[i] + "|");
}
System.out.println();
frame.getContentPane().add(list, BorderLayout.CENTER);
frame.setSize(500,500);
frame.setVisible(true);
}
}
---------- END SOURCE ----------
Release Regression From : 1.3.1_05
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Review ID: 165368)
======================================================================