I'm reading LinkedBlockingQueue code (JDK8u), and I find LinkedBlockingQueue's head field is not private, but last field is private. I can't find any particular opration with head . So why not set head to private ?
/**
* Head of linked list.
* Invariant: head.item == null
*/
transient Node<E> head;
/**
* Tail of linked list.
* Invariant: last.next == null
*/
private transient Node<E> last;
First some facts.
head field is private.head field is package private ... and it has the comment about invariants.So why did they change it?
Well I haven't been able to figure that out so far, but possible reasons might include:
head? Why not tail as well?)After spending a 20 minutes of so looking at the history on Github, I think it was probably an accident. The change appears to have happened in this commit (https://github.com/openjdk/jdk8u/commit/6f31fa54ac050d781656d6e8ed18a40b55ef5c0d) ... according to "git blame". But when I look what is in the commit, I can't see the change at all, let alone the purpose1. It is baffling.
Maybe it is clearer in the Mercurial history2.
At any rate, this whole thing is an exercise in curiosity. It doesn't matter why they changed it, and it doesn't affect any user code that they did3.
1 - The changeset description says that it is just syncing up with a private repo maintained by the original / primary author of the java.util.concurrent classes.
2 - We are looking a read-only Git mirror of the definitive Mercurial repository. It is possible that something has gotten screwed up in the creation of the mirror.
3 - ... modulo interaction with Heisenbugs already present in the user's code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With