Buggy code:
public class DefaultClusterCoordinator implements ClusterCoordinator { private final String uri ; private final ThreadFactory threadFactory = new NamedThreadFactory ( "copycat-coordinator-%d" ) ; private final ScheduledExecutorService executor ; private final CoordinatorConfig config ; private final DefaultLocalMemberCoordinator localMember ; final Map < String , AbstractMemberCoordinator > members = new ConcurrentHashMap < > ( ) ; private final CopycatStateContext context ; private final ClusterManager cluster ; private final Map < String , DefaultClusterCoordinator . ResourceHolder > resources = new ConcurrentHashMap < > ( ) ; private ScheduledFuture < ? > gossipTimer ; private final AtomicBoolean open = new AtomicBoolean ( ) ; public DefaultClusterCoordinator ( String uri , CoordinatorConfig config ) { } @ Override public Cluster cluster ( ) { } private synchronized void handleMembershipEvent ( MembershipEvent event ) { } @ Override public CoordinatorConfig config ( ) { } @ Override public LocalMemberCoordinator member ( ) { } @ Override public MemberCoordinator member ( String uri ) { } @ Override public Collection < MemberCoordinator > members ( ) { } @ Override @ SuppressWarnings ( "unchecked" ) public synchronized < T extends Resource < T > > T getResource ( String name ) { } public synchronized CompletableFuture < Void > acquireResource ( String name ) { } public synchronized CompletableFuture < Void > releaseResource ( String name ) { } private void createResources ( ) { } private CompletableFuture < Void > openResources ( ) { } private CompletableFuture < Void > closeResources ( ) { <START_BUG> List < CompletableFuture < Void > > futures = new ArrayList < > ( ) ; <END_BUG> for ( DefaultClusterCoordinator . ResourceHolder resource : resources . values ( ) ) { futures . add ( resource . state . close ( ) . thenCompose ( ( v ) -> resource . cluster . close ( ) ) ) ; } return CompletableFuture . allOf ( futures . toArray ( new CompletableFuture [ futures . size ( ) ] ) ) ; } @ Override @ SuppressWarnings ( "unchecked" ) public CompletableFuture < ClusterCoordinator > open ( ) { } @ Override public boolean isOpen ( ) { } @ Override @ SuppressWarnings ( "unchecked" ) public CompletableFuture < Void > close ( ) { } @ Override public boolean isClosed ( ) { } @ Override public String toString ( ) { } private static class ResourceRouter implements Router { private static final int PROTOCOL_ID = 1 ; private final Serializer serializer = new KryoSerializer ( ) ; private final Executor executor ; private ResourceRouter ( Executor executor ) { } @ Override public void createRoutes ( ClusterManager cluster , RaftProtocol protocol ) { } private < T extends Request , U extends Response > CompletableFuture < U > handleOutboundRequest ( String topic , T request , ClusterManager cluster ) { } @ Override public void destroyRoutes ( ClusterManager cluster , RaftProtocol protocol ) { } } @ SuppressWarnings ( "rawtypes" ) private static class ResourceHolder { private final Resource resource ; private final CoordinatedResourceConfig config ; private final ClusterManager cluster ; private final CopycatStateContext state ; private final ResourceContext context ; private ResourceHolder ( Resource resource , CoordinatedResourceConfig config , ClusterManager cluster , CopycatStateContext state , ResourceContext context ) { } } }

Fix:
List < CompletableFuture < Void > > futures = new ArrayList < > ( resources . size ( ) ) ;