Skip to content

RATIS-2769. Improve null handling and tests flagged by SonarCloud - #1656

Merged
szetszwo merged 2 commits into
apache:masterfrom
slfan1989:RATIS-2769
Oct 22, 2026
Merged

szetszwo merged 2 commits into
apache:masterfrom
slfan1989:RATIS-2769

Conversation

@slfan1989

@slfan1989 slfan1989 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Address four reliability warnings reported by SonarCloud:

https://github.com/apache/ratis/runs/119373650680

  • Explicitly reject null message content in MessageStreamImpl.streamAsync before creating a stream.
  • Check arithmetic query replies for failure or missing content and report a descriptive IOException.
  • Preserve Message.equals(Object) coverage through a parameterized test, avoiding a direct assertion between dissimilar types.
  • Refactor metadata persistence exception tests so each assertThrows lambda invokes only one operation under test.

Add regression tests for null stream content and arithmetic reply handling.

What is the link to the Apache JIRA

RATIS-2769. Improve null handling and tests flagged by SonarCloud

How was this patch tested?

unit tests & CI

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slfan1989 , thanks for working on this! Just a minor comment inlined.

Comment on lines -84 to -86
final int n = subSize.getSizeInt();
final ByteString bytes = Objects.requireNonNull(Message.toByteString(message), "message content == null");
final MessageOutputStream out = stream();
final ByteString bytes = Message.toByteString(message);

@szetszwo szetszwo Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check null at the first line:

  public CompletableFuture<RaftClientReply> streamAsync(Message message, SizeInBytes subSize) {
    Objects.requireNonNull(message, "message == null");
    final ByteString bytes = Objects.requireNonNull(Message.toByteString(message), "message content == null");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @szetszwo for the review! Updated to check message for null on the first line.

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo
szetszwo merged commit 170266e into apache:master Oct 22, 2026
16 checks passed
@slfan1989

Copy link
Copy Markdown
Contributor Author

+1 the change looks good.

Thanks @szetszwo for reviewing and merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants