Skip to content

Commit 0ccbc01

Browse files
committed
[java] fix autoclose casting
java.lang.ClassCastException: class jdk.internal.net.http.HttpClientFacade cannot be cast to class java.lang.AutoCloseable (jdk.internal.net.http.HttpClientFacade is in module java.net.http of loader 'platform'; java.lang.AutoCloseable is in module java.base of loader 'bootstrap'
1 parent 636137e commit 0ccbc01

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

java/spotbugs-excludes.xml

+5
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,9 @@
244244
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE,IS2_INCONSISTENT_SYNC"/>
245245
</Match>
246246

247+
<Match>
248+
<Class name="org.openqa.selenium.remote.http.jdk.JdkHttpClient"/>
249+
<Bug pattern="BC_VACUOUS_INSTANCEOF"/>
250+
</Match>
251+
247252
</FindBugsFilter>

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,17 @@ public void close() {
523523
}
524524
}
525525

526-
AutoCloseable closeable = (AutoCloseable) this.client;
527-
executorService.submit(
528-
() -> {
529-
try {
530-
closeable.close();
531-
} catch (Exception e) {
532-
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
533-
}
534-
});
526+
if (this.client instanceof AutoCloseable) {
527+
AutoCloseable closeable = (AutoCloseable) this.client;
528+
executorService.submit(
529+
() -> {
530+
try {
531+
closeable.close();
532+
} catch (Exception e) {
533+
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
534+
}
535+
});
536+
}
535537
this.client = null;
536538
executorService.shutdown();
537539
}

0 commit comments

Comments
 (0)