Skip to content

[🐛 Bug]: NullPointerException with jdk http client #11450

@erik-rnbt

Description

@erik-rnbt

What happened?

When trying to connect a jdk http client webdriver to a grid using a proxy (with authentication) I get a java.lang.NullPointerException.

How can we reproduce the issue?

		System.setProperty("webdriver.http.factory", "jdk-http-client");

		ChromeOptions browserOptions = new ChromeOptions();
		browserOptions.setPlatformName("Linux");

		java.net.Authenticator auth = new java.net.Authenticator() {
			public PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("username", "pwd".toCharArray());
			}
		};
		java.net.Authenticator.setDefault(auth);

		Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy", port));

		ClientConfig config = ClientConfig.defaultConfig()
				.connectionTimeout(Duration.ofSeconds(45))
				.readTimeout(Duration.ofSeconds(45))
				.proxy(proxy)
				.baseUrl(new URL("gridUrl"));

		HttpCommandExecutor executor = new HttpCommandExecutor(config);
		
		WebDriver driver = new RemoteWebDriver(executor, browserOptions);

Relevant log output

Caused by: java.lang.NullPointerException
	at java.base/java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:108)
	at org.openqa.selenium.remote.http.jdk.JdkHttpMessages.lambda$createResponse$4(JdkHttpMessages.java:149)
	at org.openqa.selenium.remote.http.Contents.bytes(Contents.java:80)
	at org.openqa.selenium.remote.http.Contents.string(Contents.java:97)
	at org.openqa.selenium.remote.http.Contents.string(Contents.java:101)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:131)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:535)
	... 3 more

Operating System

Windows 10

Selenium version

Java 4.7.2

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

all

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

all

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-javaJava BindingsI-defectSomething is not working as intendedJ-issue-templateApplied to issues not following the template, or missing information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions