commons-issues mailing list archives

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

     [ https://issues.apache.org/jira/browse/COLLECTIONS-515?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

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()
method.

{noformat}
      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,
(org.apache.commons.collections4.Transformer)var1);
      java.util.SortedMap var3 = var2.tailMap((java.lang.Object)var2);
{noformat}

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: https://issues.apache.org/jira/browse/COLLECTIONS-515
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Collection, Map
>    Affects Versions: 4.0
>         Environment: Mac OS 10.9, Java 6
>            Reporter: Cyrille Artho
>         Attachments: Report3.java
>
>
> When LazySortedMap is used by equals, the result is
> java.lang.ClassCastException: org.apache.commons.collections4.map.LazySortedMap 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
(v6.2#6252)

Mime
View raw message