You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FormalContext and PartialContext both throw a NullPointerException when attempting to remove an object not present in the context by the object's id.
The code is equivalent:
@OverridepublicbooleanremoveObject(Iid) throwsIllegalObjectException {
booleanremoved = getObjects().remove(getObject(id));
if (!removed) {
thrownewIllegalObjectException("Object" + id + "not successfully removed");
}
returntrue;
}
On the first line, getObject(id) returns null for the non-existent object. Since the objects are held in a ListSet, getObjects().remove(...) calls ListSet's overridden remove(Object o) method.
ListSet#remove():
@Overridepublicbooleanremove(Objecto) throwsNullPointerException {
if (o == null) {
thrownewNullPointerException();
}
if (contains(o)) {
this.elements.remove(o);
returntrue;
}
returnfalse;
}
As o is null, the NullPointerException is thrown instead of the IllegalObjectException that is expected.
FormalContext
andPartialContext
both throw aNullPointerException
when attempting to remove an object not present in the context by the object's id.The code is equivalent:
On the first line,
getObject(id)
returnsnull
for the non-existent object. Since the objects are held in aListSet
,getObjects().remove(...)
callsListSet
's overriddenremove(Object o)
method.ListSet#remove()
:As
o
is null, theNullPointerException
is thrown instead of theIllegalObjectException
that is expected.Test to reproduce:
The text was updated successfully, but these errors were encountered: