There was a change added in Java 7 to fix this. It was an error.
Due to an error in
java.util.TreeMap
, it was previously possible to insert invalid null elements and elements not implementingComparable
into emptyTreeMap
s andTreeSet
s. Only a single invalid element could be inserted into the emptyTreeMap
s orTreeSet
s; additional elements would cause the expectedNullPointerException
orClassCastException
. Most other operations upon the collection would also fail. As of JDK 7, inserting an invalid null element or an element not implementingComparable
into an emptyTreeMap
orTreeSet
throws aNullPointerException
.
(TreeSet
is implemented with a TreeMap
as its underlying data structure.)