Skip to content

Commit

Permalink
[bidi][java] Ensure empty values are removed from the call back map
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jul 3, 2024
1 parent 5c08747 commit 06e7b7a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion java/src/org/openqa/selenium/bidi/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.Closeable;
import java.io.StringReader;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -210,7 +211,16 @@ public void removeListener(long id) {
Lock lock = callbacksLock.writeLock();
lock.lock();
try {
eventCallbacks.forEach((k, v) -> v.remove(id));
List<Event<?>> list = new ArrayList<>();
eventCallbacks.forEach(
(k, v) -> {
v.remove(id);
if (v.isEmpty()) {
list.add(k);
}
});

list.forEach(eventCallbacks::remove);
} finally {
lock.unlock();
}
Expand Down

0 comments on commit 06e7b7a

Please sign in to comment.