Skip to content
Permalink
Browse files
CURATOR-583: Fix ArrayIndexOutOfBoundsException when passing empty li…
…st parameter to reconfigure API

This closes #374 .
  • Loading branch information
hjyun328 authored and tisonkun committed Sep 20, 2020
1 parent fdb8f79 commit 800fdf4c5cbe3f0e3cebc64357707ba743fc46e2
Showing 2 changed files with 53 additions and 4 deletions.
@@ -130,7 +130,7 @@ public StatConfigureEnsembleable withNewMembers(String... server)
@Override
public StatConfigureEnsembleable withNewMembers(List<String> servers)
{
newMembers = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
newMembers = (servers != null && !servers.isEmpty()) ? ImmutableList.copyOf(servers) : null;
return new StatConfigureEnsembleable()
{
@Override
@@ -164,7 +164,7 @@ public LeaveStatConfigEnsembleable joining(String... server)
@Override
public LeaveStatConfigEnsembleable joining(List<String> servers)
{
joining = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
joining = (servers != null && !servers.isEmpty()) ? ImmutableList.copyOf(servers) : null;

return new LeaveStatConfigEnsembleable()
{
@@ -211,7 +211,7 @@ public JoinStatConfigEnsembleable leaving(String... server)
@Override
public JoinStatConfigEnsembleable leaving(List<String> servers)
{
leaving = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
leaving = (servers != null && !servers.isEmpty()) ? ImmutableList.copyOf(servers) : null;

return new JoinStatConfigEnsembleable()
{
@@ -51,6 +51,7 @@
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -332,6 +333,54 @@ public void testAddAndRemove() throws Exception
}
}

@Test
public void testAddAndRemoveWithEmptyList() throws Exception
{
try ( CuratorFramework client = newClient())
{
client.start();

QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
assertConfig(oldConfig, cluster.getInstances());

CountDownLatch latch = setChangeWaiter(client);

Collection<InstanceSpec> oldInstances = cluster.getInstances();
client.reconfig().leaving(Collections.emptyList()).joining(Collections.emptyList()).fromConfig(oldConfig.getVersion()).forEnsemble();

Assert.assertTrue(timing.awaitLatch(latch));

byte[] newConfigData = client.getConfig().forEnsemble();
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
assertConfig(newConfig, oldInstances);
Assert.assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
}
}

@Test
public void testNewMembersWithEmptyList() throws Exception
{
try ( CuratorFramework client = newClient())
{
client.start();

QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
assertConfig(oldConfig, cluster.getInstances());

CountDownLatch latch = setChangeWaiter(client);

Collection<InstanceSpec> oldInstances = cluster.getInstances();
client.reconfig().withNewMembers(Collections.emptyList()).fromConfig(oldConfig.getVersion()).forEnsemble();

Assert.assertTrue(timing.awaitLatch(latch));

byte[] newConfigData = client.getConfig().forEnsemble();
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
assertConfig(newConfig, oldInstances);
Assert.assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
}
}

@Test(enabled = false) // it's what this test is inteded to do and it keeps failing - disable for now
public void testNewMembers() throws Exception
{
@@ -554,4 +603,4 @@ private static QuorumVerifier toQuorumVerifier(byte[] bytes) throws Exception
properties.load(new ByteArrayInputStream(bytes));
return new QuorumMaj(properties);
}
}
}

0 comments on commit 800fdf4

Please sign in to comment.