diff --git a/java/src/org/openqa/selenium/bidi/Connection.java b/java/src/org/openqa/selenium/bidi/Connection.java index dd6bce851fb22..643872ed1f0e3 100644 --- a/java/src/org/openqa/selenium/bidi/Connection.java +++ b/java/src/org/openqa/selenium/bidi/Connection.java @@ -189,13 +189,7 @@ public long addListener(Event event, Consumer handler) { Lock lock = callbacksLock.writeLock(); lock.lock(); try { - eventCallbacks.computeIfAbsent( - event, - key -> { - HashMap> map = new HashMap<>(); - map.put(id, handler); - return map; - }); + eventCallbacks.computeIfAbsent(event, key -> new HashMap<>()).put(id, handler); } finally { lock.unlock(); } @@ -217,13 +211,6 @@ public void removeListener(long id) { lock.lock(); try { eventCallbacks.forEach((k, v) -> v.remove(id)); - eventCallbacks.forEach( - (k, v) -> { - v.remove(id); - if (v.isEmpty()) { - eventCallbacks.remove(k); - } - }); } finally { lock.unlock(); }