JDK-7118652 : The TreeSet javadoc wrongly claims equals method will be used to test equality
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-12-06
  • Updated: 2021-03-03
  • Resolved: 2011-12-12
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
The TreeSet javadoc claims that the add method:
"More formally, adds the specified element e to this set if the set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false."

This is not correct, since only the comparable interface is used to assert equality in the source code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A reference to the comparable interface being used to assert equality instead of the equals method.
ACTUAL -
 More formally, adds the specified element e to this set if the set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false.

URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html#add(E)

Comments
PUBLIC COMMENTS Duplicate of 7030899
12-12-2011