[ 
https://issues.apache.org/jira/browse/RATIS-2640?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze resolved RATIS-2640.
-------------------------------
    Fix Version/s: 3.3.1
       Resolution: Fixed

The pull request is now merged.  Thanks, [~hooji] !

> AdminApi.setConfiguration(RaftPeer[], RaftPeer[]) drops the servers array and 
> always throws NullPointerException
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: RATIS-2640
>                 URL: https://issues.apache.org/jira/browse/RATIS-2640
>             Project: Ratis
>          Issue Type: Bug
>          Components: client
>    Affects Versions: 3.2.2
>            Reporter: Anony Mouse
>            Assignee: Anony Mouse
>            Priority: Major
>             Fix For: 3.3.1
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> h3. Summary
> The two-array overload {{AdminApi.setConfiguration(RaftPeer[] 
> serversInNewConf, RaftPeer[] listenersInNewConf)}} passes the *servers* array 
> into the *listeners* setter:
> {code:java}
> default RaftClientReply setConfiguration(RaftPeer[] serversInNewConf, 
> RaftPeer[] listenersInNewConf)
>     throws IOException {
>   return setConfiguration(SetConfigurationRequest.Arguments
>       .newBuilder()
>       .setListenersInNewConf(serversInNewConf)   // <-- should be 
> setServersInNewConf
>       .setListenersInNewConf(listenersInNewConf)
>       .build());
> }
> {code}
> The second call overwrites the first, so {{serversInNewConf}} is dropped 
> entirely and the builder's server list stays null. {{Arguments}}'s 
> constructor then calls {{Preconditions.assertUnique(null)}}, so *every* call 
> to this overload throws {{NullPointerException}} before a request is ever 
> sent. The overload has therefore 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.
> h3. Stack trace
> {noformat}
> java.lang.NullPointerException: Cannot invoke "java.lang.Iterable.iterator()" 
> because "original" is null
>     at 
> org.apache.ratis.util.Preconditions.assertUnique(Preconditions.java:142)
>     at 
> org.apache.ratis.util.Preconditions.assertUnique(Preconditions.java:137)
>     at 
> org.apache.ratis.protocol.SetConfigurationRequest$Arguments.<init>(SetConfigurationRequest.java:59)
>     at org.apache.ratis.client.api.AdminApi.setConfiguration(AdminApi.java:65)
> {noformat}
> h3. Affects
> Present at release 3.2.2 and on current master (7eedc1dee).
> h3. Fix
> Route the servers array through {{setServersInNewConf(...)}}, mirroring the 
> List-based overload directly above it. PR with a regression test covering 
> both two-argument overloads: https://github.com/apache/ratis/pull/1543



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to