Skip to content

RATIS-2640. Fix AdminApi.setConfiguration(RaftPeer[], RaftPeer[]) dropping the servers array - #1543

Open
hooji wants to merge 1 commit into
apache:masterfrom
hooji:fix-adminapi-setconfiguration
Open

RATIS-2640. Fix AdminApi.setConfiguration(RaftPeer[], RaftPeer[]) dropping the servers array#1543
hooji wants to merge 1 commit into
apache:masterfrom
hooji:fix-adminapi-setconfiguration

Conversation

@hooji

@hooji hooji commented Aug 3, 2026

Copy link
Copy Markdown

What changes were proposed in this pull request?

Fix the AdminApi.setConfiguration(RaftPeer[] serversInNewConf, RaftPeer[] listenersInNewConf) default method. It built its Arguments with

.setListenersInNewConf(serversInNewConf)
.setListenersInNewConf(listenersInNewConf)

so the servers array was passed to the listeners setter and then overwritten by the real listeners. The builder's server list was never set, and Arguments's constructor then hit Preconditions.assertUnique(null) — every call to this overload failed with a NullPointerException, i.e. the overload has never worked as its javadoc documents ("The same as setConfiguration(Arrays.asList(serversInNewConf), Arrays.asList(listenersInNewConf))"). No in-repo caller uses it, which is presumably why it went unnoticed.

The fix routes the servers through setServersInNewConf(...), mirroring the List-based overload directly above it, and adds a regression test (org.apache.ratis.client.TestAdminApi in ratis-test) that captures the built Arguments through a stub AdminApi and asserts both two-argument overloads.

Found while evaluating Ratis for adoption; present at ratis-3.2.2 and on current master (7eedc1d).

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-2640

How was this patch tested?

New unit test org.apache.ratis.client.TestAdminApi:

  • Before the fix: testSetConfigurationWithArrays fails with
    java.lang.NullPointerException ... at org.apache.ratis.util.Preconditions.assertUnique(Preconditions.java:142) ... at org.apache.ratis.protocol.SetConfigurationRequest$Arguments.<init>(SetConfigurationRequest.java:59) ... at org.apache.ratis.client.api.AdminApi.setConfiguration(AdminApi.java:65)
  • After the fix: Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Also ran checkstyle:check and apache-rat:check on the changed modules (clean). Built and tested with JDK 21.

🤖 Generated with Claude Code

…rvers array

The two-array overload built its Arguments with
setListenersInNewConf(serversInNewConf) followed by
setListenersInNewConf(listenersInNewConf), so the servers were dropped
and the builder's server list stayed null; every call to this overload
then failed with a NullPointerException from Preconditions.assertUnique
in the Arguments constructor. Route the servers through
setServersInNewConf, as the javadoc documents, and add a regression
test covering both two-argument overloads.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@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.

@hooji , Good catch on the bug!

+1 the change looks good.

@szetszwo

szetszwo commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@hooji , could you file a JIRA? We, Apache Ratis, use JIRA to track issues.

@hooji

hooji commented Aug 4, 2026

Copy link
Copy Markdown
Author

Sorry, I'm not on JIRA. We just noticed the bug while doing an AI survey of the code prior to making a decision between Ratis and SOFAJRaft. Can you file the JIRA for us?

Here's a copy of the final evaluation if you're interested. Written by Fable 5:

RAFT_LIBRARY_EVALUATION.md

@adoroszlai

Copy link
Copy Markdown
Contributor

Sorry, I'm not on JIRA.

@hooji Your request for a Jira user is approved, now you can proceed creating the issue. Thanks.

@hooji hooji changed the title Fix AdminApi.setConfiguration(RaftPeer[], RaftPeer[]) dropping the servers array RATIS-2640. Fix AdminApi.setConfiguration(RaftPeer[], RaftPeer[]) dropping the servers array Aug 4, 2026
@hooji

hooji commented Aug 4, 2026

Copy link
Copy Markdown
Author

JIRA 2640 filed

@adoroszlai
adoroszlai requested a review from szetszwo August 4, 2026 12:42
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.

3 participants