From 0f7cef0cf7a4fa40d3ad68ad908181a06205b077 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Mon, 21 Mar 2022 18:04:23 +0800 Subject: [PATCH] fix prev may change after empty judgment Change-Id: I6814e588c67018b13fcefbc373f02912dbf08c6a --- .../java/com/baidu/hugegraph/backend/cache/RamCache.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java index be2b44b089..0bfda706db 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java @@ -395,6 +395,7 @@ public LinkNode enqueue(LinkNode node) { while (true) { LinkNode last = this.rear.prev; + assert last != this.empty : last; // TODO: should we lock the new `node`? List locks = this.lock(last, this.rear); @@ -446,7 +447,7 @@ public LinkNode dequeue() { } // Break the link between the `head` and `first` - assert first.next != null; + assert first.next != null && first.next != this.empty; this.head.next = first.next; first.next.prev = this.head; @@ -469,12 +470,12 @@ public LinkNode remove(LinkNode node) { assert node != this.head && node != this.rear; while (true) { - if (node.prev == this.empty || node.next == this.empty) { + LinkNode prev = node.prev; + if (prev == this.empty || node.next == this.empty) { // Ignore the `node` if it has been removed return null; } - LinkNode prev = node.prev; List locks = this.lock(prev, node); try { if (prev != node.prev) {