javanullpointerexceptionjava.util.concurrentibm-jre

Impossible (?): NullPointerException on ConcurrentLinkedQueue.size()


I'm getting this NPE on IBM JVM, 1.6:

java.lang.NullPointerException at java.util.concurrent.ConcurrentLinkedQueue.first(ConcurrentLinkedQueue.java:274) at java.util.concurrent.ConcurrentLinkedQueue.size(ConcurrentLinkedQueue.java:315) . . .

Relevant source shows that line #274 throws on a null "head" member. Search for usages shows this member is set to a new node() as needed, but is never nullified.

How could that be? What am I missing?

... I cannot reproduce this when in debug mode. This queue is accessed from multiple threads.

Snippet (Sun&IBM sources identical except for comments that change line numbers a bit):

     Node<E> first() {
                for (;;) {
                    Node<E> h = head;
                    Node<E> t = tail;
                    Node<E> first = h.getNext(); // line #274 on IBM, #263 on Sun
...
    }
    }

Solution

  • Errors like that often come from the JIT compiler which gets some arcane optimization wrong.

    There is little you can do; log error with IBM, they will then guide you through the process how to collect enough information for them to debug the issue.

    Note: In the last years, we filed two such issues. So they aren't that uncommon even taking into account the enormous testing effort that IBM spends on their VM.