-
Bug
-
Resolution: Unresolved
-
P3
-
None
-
6
-
Cause Known
-
generic
-
generic
Spec of the CompoundEdit.addEdit() method does not specify the behavior for null parameter.
This is not only documentation bug. It leads to several confusions in current RI: if lastEdit() returns null, null edit will be added to collection of subedits. Otherwise NullPointerException could be thrown (if last edit refuses to add null edit). Besides if null edit was added to the collection of subedits, then other methods can throw nullPointerException. Namely, all methods of CompoundEdit class acting on subedits (undo(), redo(), die(), ) throw NullPointerException, which is not mentioned in corresponding descriptions.
To reproduce these failures use the following code:
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CompoundEdit;
public class StubCompoundEdit extends CompoundEdit {
public static void main(String[] args) {
CompoundEdit compoundEdit = new CompoundEdit(); // Create CompoundEdit object
//lastEdit() returns null -> successfully add null edit
compoundEdit.addEdit(null);
compoundEdit.end();
boolean failed = false;
try {
compoundEdit.undo();
} catch (Throwable e) {
failed = true;
System.out.println("compoundEdit.undo() throws " + e);
}
compoundEdit = new CompoundEdit(); // Create CompoundEdit object compoundEdit.addEdit(new AbstractUndoableEdit());
// lastEdit() returns not null
try {
compoundEdit.addEdit(null);
} catch (Throwable e) {
failed = true;
System.out.println("addEdit(null) throws " + e);
}
if (!failed) {
System.out.println("OK");
}
}
}
###@###.### 2005-2-18 09:07:08 GMT
This is not only documentation bug. It leads to several confusions in current RI: if lastEdit() returns null, null edit will be added to collection of subedits. Otherwise NullPointerException could be thrown (if last edit refuses to add null edit). Besides if null edit was added to the collection of subedits, then other methods can throw nullPointerException. Namely, all methods of CompoundEdit class acting on subedits (undo(), redo(), die(), ) throw NullPointerException, which is not mentioned in corresponding descriptions.
To reproduce these failures use the following code:
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CompoundEdit;
public class StubCompoundEdit extends CompoundEdit {
public static void main(String[] args) {
CompoundEdit compoundEdit = new CompoundEdit(); // Create CompoundEdit object
//lastEdit() returns null -> successfully add null edit
compoundEdit.addEdit(null);
compoundEdit.end();
boolean failed = false;
try {
compoundEdit.undo();
} catch (Throwable e) {
failed = true;
System.out.println("compoundEdit.undo() throws " + e);
}
compoundEdit = new CompoundEdit(); // Create CompoundEdit object compoundEdit.addEdit(new AbstractUndoableEdit());
// lastEdit() returns not null
try {
compoundEdit.addEdit(null);
} catch (Throwable e) {
failed = true;
System.out.println("addEdit(null) throws " + e);
}
if (!failed) {
System.out.println("OK");
}
}
}
###@###.### 2005-2-18 09:07:08 GMT