Skip to content

[🐛 Bug]: NullPointerException while using DevTools instance with JDK 11 Http Client #12882

Closed
@pujagani

Description

@pujagani

What happened?

Using JDK 11 Http Client prevents reusing of DevTools instance. Earlier, this was not a problem since Selenium used a single instance of AsyncHttpClient and it was only closed when the JVM shuts down. But with the JdkHttpClient, Selenium uses a new instance each time and closes it too.
Changes made as part of #11345, which assigns the client to null while closing causes an NPE when re-using DevTools instance. The changes were made to prevent memory leaks.

I am not sure about the right approach to address this. I will need to look into it further.

How can we reproduce the issue?

Run https://github.com/SeleniumHQ/selenium/blob/trunk/java/test/org/openqa/selenium/devtools/DevToolsReuseTest.java with JDK 11 Http Client

Relevant log output

Cannot invoke "java.net.http.HttpClient.newWebSocketBuilder()" because "this.client" is null
java.lang.NullPointerException: 
	at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:168)
	at org.openqa.selenium.devtools.Connection.reopen(Connection.java:92)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:129)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:117)
	at org.openqa.selenium.devtools.DevToolsReuseTest.shouldBeAbleToCloseDevToolsAndCreateNewInstance(DevToolsReuseTest.java:41)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Operating System

macOS Ventura

Selenium version

Java 4.13.0

What are the browser(s) and version(s) where you see this issue?

Chrome 117

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver Version: 117.0.5938.149

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-devtoolsIncludes everything BiDi or Chrome DevTools relatedC-javaJava BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions