Skip to content

[BUG] possible NPE in RestTasksAction.java found by SAST #17762

@ngr-ilmarh

Description

@ngr-ilmarh

Describe the bug

Hello.

We've analyzed Opensearch sources with SAST and it pointed out possible NPE in

table.addCell(node.getAddress().address().getPort());

        table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4));
        table.addCell(node == null ? "-" : node.getHostAddress());
        table.addCell(node.getAddress().address().getPort());
        table.addCell(node == null ? "-" : node.getName());
        table.addCell(node == null ? "-" : node.getVersion().toString());

I think this code should look identical in every node access:

        table.addCell(node == null ? "-" : node.getHostAddress());
        table.addCell(node == null ? "-" : node.getAddress().address().getPort());
        table.addCell(node == null ? "-" : node.getName());
        table.addCell(node == null ? "-" : node.getVersion().toString());```  



### Related component

_No response_

### To Reproduce

Didn't catch it in action, just static analysis of the code

### Expected behavior

From the comments in the code if node will left the cluster, then no metadata will be available and not even ip address of the node should be '-', but port also 

### Additional Details


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions