Skip to content

Commit 06e7b7a

Browse files
committed
[bidi][java] Ensure empty values are removed from the call back map
1 parent 5c08747 commit 06e7b7a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

java/src/org/openqa/selenium/bidi/Connection.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.Closeable;
2626
import java.io.StringReader;
2727
import java.time.Duration;
28+
import java.util.ArrayList;
2829
import java.util.HashMap;
2930
import java.util.List;
3031
import java.util.Map;
@@ -210,7 +211,16 @@ public void removeListener(long id) {
210211
Lock lock = callbacksLock.writeLock();
211212
lock.lock();
212213
try {
213-
eventCallbacks.forEach((k, v) -> v.remove(id));
214+
List<Event<?>> list = new ArrayList<>();
215+
eventCallbacks.forEach(
216+
(k, v) -> {
217+
v.remove(id);
218+
if (v.isEmpty()) {
219+
list.add(k);
220+
}
221+
});
222+
223+
list.forEach(eventCallbacks::remove);
214224
} finally {
215225
lock.unlock();
216226
}

0 commit comments

Comments
 (0)