lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler (JIRA)" <>
Subject [jira] Commented: (LUCENE-2953) PriorityQueue is inheriently broken if subclass attempts to use "heap" w/generic T bound to anything other then "Object"
Date Tue, 08 Mar 2011 09:05:59 GMT


Uwe Schindler commented on LUCENE-2953:

The easy and most simply way to handle this is osing Object[] like in ArrayList.

The problem with then always casting from Object to T is thousands of unchecked warnings in
PriorityQueue. I would propose the following:
In general the final T[] heap variable should be private to the PQ and used only there. For
performance yonik wanted the heap[] protected and that caused the issue. As long as the heap[]
array is private it can never be accessed incorrectly.

So my proposal is to internally use the T[] as a private field and simply use another Object[]
thats protected (pointing to the same array). This would fix the problem. The most correct
idea would be to add a setHeapSlot(int, T o) and T getHeapSlot(int) method and hiding the
T[] heap completely, but I know, Yonik will disagree :-)

There is some other problem: the heap array should be final, but it cannot, because of the
stupid initialize() method. I would like to remove this method and simply move the code to
PQ's ctor. I don't understand why the initialize() method is there, which is a problem: Every
guide on Java programming tells you to never call protected overrideable methods from ctors,
as this can break easily. If the heap[] is final, the problem of having two references to
the same object is not a problem anymore.

> PriorityQueue is inheriently broken if subclass attempts to use "heap" w/generic T bound
to anything other then "Object"
> ------------------------------------------------------------------------------------------------------------------------
>                 Key: LUCENE-2953
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Bug
>            Reporter: Hoss Man
>         Attachments:, LUCENE-2953.patch
> as discovered in SOLR-2410 the fact that the protected "heap" variable in PriorityQueue
is initialized using an Object[] makes it impossible for subclasses of PriorityQueue to exist
and access the "heap" array unless they bind the generic to Object.

This message is automatically generated by JIRA.
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message