diff --git a/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java b/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java index 20a8f26ef..1e076f5ca 100644 --- a/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java +++ b/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java @@ -118,6 +118,7 @@ public T takeFirst() throws InterruptedException { while (true) { if (length > 0) { entry = deque[start]; + deque[start] = null; start = (start + 1) % limit; length--; break; @@ -155,7 +156,9 @@ public T takeLast() throws InterruptedException { synchronized (mutex) { while (true) { if (length > 0) { - entry = deque[(start + length - 1) % limit]; + int idx = (start + length - 1) % limit; + entry = deque[idx]; + deque[idx] = null; length--; break; }