Skip to content

Commit b81b144

Browse files
authored
fix: null check in ListenerCollection notify method (#1661)
1 parent 256e41a commit b81b144

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/ListenerCollection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.microsoft.playwright.impl;
1818

1919
import com.google.gson.JsonObject;
20+
import com.microsoft.playwright.PlaywrightException;
2021

2122
import java.util.*;
2223
import java.util.function.Consumer;
@@ -46,6 +47,9 @@ <T> void notify(EventType eventType, T param) {
4647
}
4748

4849
void add(EventType type, Consumer<?> listener) {
50+
if (listener == null) {
51+
throw new PlaywrightException("Can't add a null listener");
52+
}
4953
List<Consumer<?>> list = listeners.get(type);
5054
if (list == null) {
5155
list = new ArrayList<>();

playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,13 @@ void shouldPropagateCloseReasonToPendingActions() {
347347
}));
348348
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
349349
}
350+
351+
@Test
352+
void shouldProhibitNullListeners() {
353+
Page newPage = context.newPage();
354+
355+
PlaywrightException e = assertThrows(PlaywrightException.class, () -> newPage.onClose(null));
356+
357+
assertTrue(e.getMessage().contains("Can't add a null listener"));
358+
}
350359
}

0 commit comments

Comments
 (0)