[ https://issues.apache.org/jira/browse/SOLR-2410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003675#comment-13003675 ]
Dawid Weiss commented on SOLR-2410: ----------------------------------- It's because there's a bug -- PriorityQueue declares a generic array: protected T[] heap; but assigns an Object[] to it in: heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works always this is true only if heap is not exposed outside the class (and is the pattern used in JDK's ArrayDeque<E>, for example). Unfortunately the compiler will insert casts if you have a subclass with a narrowed generic type to ensure the array is indeed of proper type. The solution is to: 1) allocate arrays of real component type (impossible if you don't know it in advance or don't have an existing array or its component). Example: Google Guava's ObjectArrays.newArray, as here: http://guava-libraries.googlecode.com/svn/tags/release08/javadoc/com/google/common/collect/ObjectArrays.html#newArray(java.lang.Class, int) 2) cast superclass's array to (Object[]) first, then cast to the concrete component type. Here: (CacheEntry<K,V>) ((Object[]) heap)[1]; 3) Declare PriorityQueue's internal array as Object[] and provide a getter that casts components to (T)? > ConcurrentLRUCache can throw class cast exception > ------------------------------------------------- > > Key: SOLR-2410 > URL: https://issues.apache.org/jira/browse/SOLR-2410 > Project: Solr > Issue Type: Bug > Affects Versions: 4.0 > Reporter: Yonik Seeley > Fix For: 4.0 > > > ConcurrentLRUCache throws a class cast exception. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org