gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 374 forks source link

TreeSet/TreeMap equals() ClassCastException for incomparable elements #3599

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 3594

Found in GWT Release (e.g. 1.5.3, 1.6 RC) / Encountered on OS / Browser
(e.g. WinXP, IE6-7, FF3):

GWT unit test in the internal GWT release.  Let me know if that's
insufficient info, and I'll follow up internally.

Detailed description (please be as specific as possible):

TreeSet.equals() (plus TreeMap.equals(), I'm guessing) throws a
ClassCastException when checking for the presence of an incomparable
element from the other set.  The JDK catches such exceptions in equals()
and returns false, but GWT lets them propagate.  I don't know that this is
strictly a bug, but it's a difference from the JDK API.

Shortest code snippet which demonstrates issue (please indicate where
actual result differs from expected result):

TreeSet<Integer> ints = new TreeSet<Integer>();
ints.add(1);
HashSet<String> strings = new HashSet<Integer>();
strings.add("one");
ints.equals(strings); // throws CCE instead of returning false

Workaround if you have one:

Manually catch the ClassCastException and treat it as a false result.

Links to relevant GWT Developer Forum posts:

none

Reported by cpovirk+external@google.com on 2009-04-24 21:35:38

dankurka commented 9 years ago

Reported by dankurka@google.com on 2013-05-27 22:14:03

dankurka commented 9 years ago
Still reproducible with the code snippet given above.

Reported by cpovirk@google.com on 2013-07-08 18:04:47

dankurka commented 9 years ago

Reported by dankurka@google.com on 2013-07-08 20:57:12