Skip to content

Commit fccedd8

Browse files
committed
Add a comment why FutureLinkedList is fine
1 parent 98bb496 commit fccedd8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/src/main/java/dev/failsafe/internal/util/FutureLinkedList.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public synchronized CompletableFuture<Void> pollFirst() {
6767
return previousHead == null ? null : previousHead.future;
6868
}
6969

70+
/*
71+
* This looks dodgy: we are 'leaking' reference to the node object via future.whenComplete, so
72+
* this can end up being called for a node that has already been removed. This could have caused
73+
* problems. But in reality it currently would not because the only way to remove a node is via
74+
* pollFirst - i.e. by polling from the head of the list. This means that if node passed to this
75+
* function has already been removed it would imply that it's 'previous' field is always null
76+
* (it was in the head of the list before removal). And it's 'next' points to current head of
77+
* the list, so when we replace node.next.previous with node.previous we always replace null
78+
* with null. This whole assumption would break it this list allowed to add from the head of the
79+
* list, or remove from the tail or middle. So this is somewhat fragile, but currently seems to
80+
* be working fine.
81+
*/
7082
private synchronized void remove(Node node) {
7183
if (node.previous != null)
7284
node.previous.next = node.next;

0 commit comments

Comments
 (0)