Skip to content

Commit 02562d4

Browse files
committed
fix potential NPE in tearDown methods
Also, reset the link to static field after test run - to avoid holding heavy objects in memory till the end of all tests.
1 parent 15421a2 commit 02562d4

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

java/test/org/openqa/selenium/ReferrerTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ public void startServers() {
114114

115115
@AfterEach
116116
public void stopServers() {
117-
safelyCall(() -> proxyServer.stop());
118-
safelyCall(() -> server1.stop());
119-
safelyCall(() -> server2.stop());
117+
if (proxyServer != null) {
118+
safelyCall(() -> proxyServer.stop());
119+
}
120+
if (server1 != null) {
121+
safelyCall(() -> server1.stop());
122+
}
123+
if (server2 != null) {
124+
safelyCall(() -> server2.stop());
125+
}
120126
}
121127

122128
private WebDriver createDriver(String pacUrl) {

java/test/org/openqa/selenium/devtools/CdpFacadeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static void startServer() {
5656
@AfterAll
5757
public static void stopServer() {
5858
safelyCall(() -> server.stop());
59+
server = null;
5960
}
6061

6162
@Test

java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ void ensureBiDiSessionCreation() {
9696
@Ignore(IE)
9797
@Ignore(SAFARI)
9898
void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutException {
99-
driver = new Augmenter().augment(driver);
100-
10199
try (LogInspector logInspector = new LogInspector(driver)) {
102100
CompletableFuture<ConsoleLogEntry> future = new CompletableFuture<>();
103101
logInspector.onConsoleEntry(future::complete);
@@ -135,11 +133,14 @@ void canNavigateToUrl() {
135133

136134
@AfterEach
137135
void clean() {
138-
driver.quit();
136+
if (driver != null) {
137+
driver.quit();
138+
}
139139
}
140140

141141
@AfterAll
142142
static void stopServer() {
143143
server.stop();
144+
server = null;
144145
}
145146
}

java/test/org/openqa/selenium/grid/sessionmap/jdbc/JdbcBackedSessionMapTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ public static void createDB() throws SQLException {
5959

6060
@AfterAll
6161
public static void killDBConnection() throws SQLException {
62-
connection.close();
63-
bus.close();
62+
if (connection != null) {
63+
connection.close();
64+
connection = null;
65+
}
66+
if (bus != null) {
67+
bus.close();
68+
bus = null;
69+
}
6470
}
6571

6672
@Test

java/test/org/openqa/selenium/safari/CrossDomainTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public static void startSecondServer() {
4949

5050
@AfterAll
5151
public static void stopSecondServer() {
52-
otherServer.stop();
52+
if (otherServer != null) {
53+
otherServer.stop();
54+
otherServer = null;
55+
}
56+
otherPages = null;
5357
}
5458

5559
@Test

0 commit comments

Comments
 (0)