I'm running JFreeChart 1.0.14 ( and JCommon 1.0.17).
I have an issue with the XYSeriesCollection when trying to change the key of a series.
The methode getSeries(Comparable key) throws an UnknownKeyException if key is not found in the collection.
Code: Select all
public XYSeries getSeries(Comparable key) {
if (key == null) {
throw new IllegalArgumentException("Null 'key' argument.");
}
Iterator iterator = this.data.iterator();
while (iterator.hasNext()) {
XYSeries series = (XYSeries) iterator.next();
if (key.equals(series.getKey())) {
return series;
}
}
throw new UnknownKeyException("Key not found: " + key);
}
Code: Select all
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException {
// if it is not the series name, then we have no interest
if (!"Key".equals(e.getPropertyName())) {
return;
}
// to be defensive, let's check that the source series does in fact
// belong to this collection
Series s = (Series) e.getSource();
if (getSeries(s.getKey()) == null) {
throw new IllegalStateException("Receiving events from a series " +
"that does not belong to this collection.");
}
// check if the new series name already exists for another series
Comparable key = (Comparable) e.getNewValue();
if (this.getSeries(key) != null) {
throw new PropertyVetoException("Duplicate key2", e);
}
}
I'm using a corrected version of the XYSeriesCollection at the moment, where getSeries(Comparable key) returns null if a series does not exist.
Is this a bug?
Thanks,
Nik