Skip to content

Commit ad92541

Browse files
authored
[grid][java] fix node-docker (#13789)
* [grid][java] fix node-docker Fixed: SeleniumHQ/docker-selenium#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 <[email protected]> * [grid][java]: fix node-docker Fixed exception: Caused by: java.lang.IllegalArgumentException: non-positive contentLength: 0 Signed-off-by: Viet Nguyen Duc <[email protected]> --------- Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent a0210e3 commit ad92541

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public Result check() {
279279
try {
280280
NodeStatus status = getStatus();
281281

282-
if (!Objects.equals(getId(), status.getNodeId())) {
282+
if (status.getNodeId() != null && !Objects.equals(getId(), status.getNodeId())) {
283283
// ensure the original RemoteNode stays DOWN when it has been restarted and registered
284284
// again as another RemoteNode with the same externalUri
285285
return new Result(DOWN, externalUri + " has unexpected node id");

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ public java.net.http.HttpRequest createRequest(HttpRequest req, HttpMethod metho
118118
private BodyPublisher notChunkingBodyPublisher(HttpRequest req) {
119119
Contents.Supplier content = req.getContent();
120120

121-
// we know the length of the request and use it
122-
BodyPublisher chunking = BodyPublishers.ofInputStream(content);
123-
124-
return BodyPublishers.fromPublisher(chunking, content.length());
121+
// Check if the content length is greater than 0
122+
if (content.length() > 0) {
123+
// we know the length of the request and use it
124+
BodyPublisher chunking = BodyPublishers.ofInputStream(content);
125+
return BodyPublishers.fromPublisher(chunking, content.length());
126+
} else {
127+
// If the content length is 0, return a BodyPublisher without body
128+
return BodyPublishers.noBody();
129+
}
125130
}
126131

127132
public URI getRawUri(HttpRequest req) {

0 commit comments

Comments
 (0)