-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta
-
sparc
-
solaris_2.6
Name: sdC67446 Date: 10/01/99
The method
public EventListener[] getListeners(Class listenerType)
of class
javax.swing.AbstractListModel
throws ClassCastException if 'listenerType' is not
ListDataListener.class.
The doc says:
--------------------------------------------------
public EventListener[] getListeners(Class listenerType)
Return an array of all the listeners of the given type that were
added to this model.
Since:
1.3
The demo test:
--------------------------------------------------
import javax.swing.*;
import javax.swing.event.*;
public class Test {
public static class FakeListDataListener implements ListDataListener {
public void intervalAdded(ListDataEvent event) {}
public void intervalRemoved(ListDataEvent event) {}
public void contentsChanged(ListDataEvent event) {}
}
public static class StubListModel extends AbstractListModel {
public int getSize() { return 10; }
public Object getElementAt(int index) { return null; }
public void fireContentsChanged(Object object, int index0, int index1) {
super.fireContentsChanged(object,index0,index1);
}
public void fireIntervalAdded(Object object, int index0, int index1) {
super.fireIntervalAdded(object,index0,index1);
}
public void fireIntervalRemoved(Object object, int index0, int index1) {
super.fireIntervalRemoved(object,index0,index1);
}
}
public static void main(String argv[]) {
StubListModel model = new StubListModel();
FakeListDataListener l = new FakeListDataListener();
try {
System.out.println("1");
model.addListDataListener(l);
model.getListeners(ListDataListener.class);
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("2");
model.addListDataListener(l);
model.getListeners(Integer.class);
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("3");
model.addListDataListener(l);
model.getListeners(StubListModel.class);
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
--------------------------------------------------
1
OK
2
java.lang.ClassCastException: [Ljava.lang.Integer;
at javax.swing.event.EventListenerList.getListeners(EventListenerList.java:124)
at javax.swing.AbstractListModel.getListeners(AbstractListModel.java:156)
at Test.main(Test.java:40)
3
java.lang.ClassCastException: [LTest$StubListModel;
at javax.swing.event.EventListenerList.getListeners(EventListenerList.java:124)
at javax.swing.AbstractListModel.getListeners(AbstractListModel.java:156)
at Test.main(Test.java:48)
--------------------------------------------------
======================================================================
Name: sdC67446 Date: 10/12/99
The same problem:
1) in javax.swing.DefaultBoundedRangeModel
The method public EventListener[] getListeners(Class listenerType)
of class javax.swing.DefaultBoundedRangeModel
throws ClassCastException if 'listenerType' is not
ChangeListener.class.
2) in javax.swing.DefaultListSelectionModel
The method public EventListener[] getListeners(Class listenerType)
of class javax.swing.DefaultListSelectionModel
throws ClassCastException if 'listenerType' is not
ListSelectionListener.class.
======================================================================