commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <>
Subject [jira] [Resolved] (COLLECTIONS-515) ClassCastException in LazySortedMap when used with equals/transformers
Date Thu, 10 Apr 2014 20:48:15 GMT


Thomas Neidhart resolved COLLECTIONS-515.

    Resolution: Invalid

There is no surprise here to get a ClassCastException as you provide a wrong key to the tailMap()

      org.apache.commons.collections4.trie.PatriciaTrie var0 = new org.apache.commons.collections4.trie.PatriciaTrie();
      org.apache.commons.collections4.Transformer var1 = org.apache.commons.collections4.functors.ExceptionTransformer.exceptionTransformer();
      java.util.SortedMap var2 = org.apache.commons.collections4.MapUtils.lazySortedMap((java.util.SortedMap)var0,
      java.util.SortedMap var3 = var2.tailMap((java.lang.Object)var2);

So var2 is a PatriciaTrie, and you try to construct a tailMap with the trie itself as key.
Of course this will result in a ClassCastException, the only surprise here is that it is not
thrown immediately.

Trying the same with a java.util.TreeMap will throw the ClassCastException immediately during
the call to tailMap.

> ClassCastException in LazySortedMap when used with equals/transformers
> ----------------------------------------------------------------------
>                 Key: COLLECTIONS-515
>                 URL:
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Collection, Map
>    Affects Versions: 4.0
>         Environment: Mac OS 10.9, Java 6
>            Reporter: Cyrille Artho
>         Attachments:
> When LazySortedMap is used by equals, the result is
> java.lang.ClassCastException: cannot
be cast to java.lang.String
> This seems to be odd, as the use of the different transformations should not result in
internal casting to String. See the attached unit test to reproduce.

This message was sent by Atlassian JIRA

View raw message