Inconsistencies in TreeSet Interface

Kishor Gollapalliwar kishor.gollapalliwar at gmail.com
Sat Oct 13 14:26:27 UTC 2018


Hello Everyone,

Introduction : I’m an enthusiast java developer. I’m a newbie in this
group, hence please ignore my nuisance and guide me towards right direction.

## Problems Statement

Treeset#add method documentations : “adds the specified element e to this
set if the set contains no element e2 such that (e==null ? e2==null :
e.equals(e2))”

Inconsistencies:

> If we try to add “null” value, it will throws NullPointerException, hence
> e and e2 can not be null.



> And e.compareTo(e2) ==0 || compare(e, e2)==0, it will not add to
> collection.


Request you to help me understand if behavior of Treeset#add method is as
expected, and differ with set interface documentation. We may have to
consider to update method documentations, if behavior is expected.

For more details I have attached the sample java application.

I’ve tested the behavior on Orack JDK 8u181 (64 bit) and Open JDK 8u181.

Thanks & Regards,
*Kishor Golapelliwar,*
The ability to convert ideas to things is the secret to outward success.


More information about the jdk8u-dev mailing list