Skip to content

Commit

Permalink
[grid][java] fix node-docker (SeleniumHQ#13789)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
VietND96 committed Apr 10, 2024
1 parent a0210e3 commit ad92541
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ad92541

Please sign in to comment.