From 5fa04971f788a296442845c8375e8a14ce68fe55 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Mon, 8 Apr 2024 18:58:21 +0000 Subject: [PATCH 1/2] [grid][java] fix node-docker Fixed: https://github.com/SeleniumHQ/docker-selenium/issues/2175 Exception in thread "Thread-0" java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.grid.node.Node.getStatus()" because "this.node" is null Signed-off-by: Viet Nguyen Duc --- java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java b/java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java index dccbb0d5d5a5c..913909b9a93ff 100644 --- a/java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java +++ b/java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java @@ -279,7 +279,7 @@ public Result check() { try { NodeStatus status = getStatus(); - if (!Objects.equals(getId(), status.getNodeId())) { + if (status.getNodeId() != null && !Objects.equals(getId(), status.getNodeId())) { // ensure the original RemoteNode stays DOWN when it has been restarted and registered // again as another RemoteNode with the same externalUri return new Result(DOWN, externalUri + " has unexpected node id"); From 2e269d49bc80f22220a491f7bf9c7ef24b581558 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 10 Apr 2024 03:58:17 +0000 Subject: [PATCH 2/2] [grid][java]: fix node-docker Fixed exception: Caused by: java.lang.IllegalArgumentException: non-positive contentLength: 0 Signed-off-by: Viet Nguyen Duc --- .../selenium/remote/http/jdk/JdkHttpMessages.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java index ccf41787ee14c..22d47eda29e19 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java @@ -118,10 +118,15 @@ public java.net.http.HttpRequest createRequest(HttpRequest req, HttpMethod metho private BodyPublisher notChunkingBodyPublisher(HttpRequest req) { Contents.Supplier content = req.getContent(); - // we know the length of the request and use it - BodyPublisher chunking = BodyPublishers.ofInputStream(content); - - return BodyPublishers.fromPublisher(chunking, content.length()); + // Check if the content length is greater than 0 + if (content.length() > 0) { + // we know the length of the request and use it + BodyPublisher chunking = BodyPublishers.ofInputStream(content); + return BodyPublishers.fromPublisher(chunking, content.length()); + } else { + // If the content length is 0, return a BodyPublisher without body + return BodyPublishers.noBody(); + } } public URI getRawUri(HttpRequest req) {