From 5c087471ad161f84598df38e34caf8b4fb3ddb4e Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Tue, 2 Jul 2024 13:11:54 +0530 Subject: [PATCH] [bidi] [java] Fix the adding and the removing listener --- java/src/org/openqa/selenium/bidi/Connection.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) 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(); }