From 3cbb56cfcad55a23fbc42569d76ac41854652e0c Mon Sep 17 00:00:00 2001 From: Robinson Date: Sat, 1 May 2021 00:28:29 +0200 Subject: [PATCH] Fixed exceptions when removing values that don't exist from bi-maps --- src/dorkbox/util/collections/LockFreeIntBiMap.java | 4 +++- src/dorkbox/util/collections/LockFreeObjectIntBiMap.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dorkbox/util/collections/LockFreeIntBiMap.java b/src/dorkbox/util/collections/LockFreeIntBiMap.java index 07475f0..2d922dd 100644 --- a/src/dorkbox/util/collections/LockFreeIntBiMap.java +++ b/src/dorkbox/util/collections/LockFreeIntBiMap.java @@ -300,7 +300,9 @@ class LockFreeIntBiMap { public synchronized V remove(final int key) { V value = forwardHashMap.remove(key); - reverseHashMap.remove(value, defaultReturnValue); + if (value != null) { + reverseHashMap.remove(value, defaultReturnValue); + } return value; } diff --git a/src/dorkbox/util/collections/LockFreeObjectIntBiMap.java b/src/dorkbox/util/collections/LockFreeObjectIntBiMap.java index cf40ef0..55cd158 100644 --- a/src/dorkbox/util/collections/LockFreeObjectIntBiMap.java +++ b/src/dorkbox/util/collections/LockFreeObjectIntBiMap.java @@ -276,7 +276,9 @@ class LockFreeObjectIntBiMap { public synchronized int remove(final V key) { int value = forwardHashMap.remove(key, defaultReturnValue); - reverseHashMap.remove(value); + if (value != defaultReturnValue) { + reverseHashMap.remove(value); + } return value; }