Source:
<code>private <C extends WriteCommand, Container, Item> void handleLocalSegmentsForReadWriteManyCommand( InvocationContext ctx, C command, WriteManyCommandHelper<C, Container, Item> helper, ConsistentHash ch, MergingCompletableFuture<Object> allFuture, MutableInt offset, IntSet segments) throws Exception { Container myItems = helper.newContainer(); <START> List<Object> remoteKeys = new ArrayList<>(); <END> for (Item item : helper.getItems(command)) { Object key = helper.item2key(item); if (segments.contains(keyPartitioner.getSegment(key))) { helper.accumulate(myItems, item); CacheEntry cacheEntry = ctx.lookupEntry(key); if (cacheEntry == null) { if (command.hasAnyFlag(FlagBitSets.SKIP_REMOTE_LOOKUP | FlagBitSets.CACHE_MODE_LOCAL)) { entryFactory.wrapExternalEntry(ctx, key, null, false, true); } else { remoteKeys.add(key); } } } } CompletionStage<Void> retrievals = remoteGetMany(ctx, command, remoteKeys); int size = helper.containerSize(myItems); if (size == 0) { allFuture.countDown(); return; } final int myOffset = offset.value; offset.value += size; C localCommand = helper.copyForLocal(command, myItems); localCommand.setTopologyId(command.getTopologyId()); InvocationFinallyAction handler = createLocalInvocationHandler(ch, allFuture, segments, helper, MergingCompletableFuture.moveListItemsToFuture(myOffset)); if (remoteKeys.isEmpty()) { invokeNextAndFinally(ctx, localCommand, handler); } else { Object result = asyncInvokeNext(ctx, command, retrievals); makeStage(result).andFinally(ctx, command, handler); } }</code><technical_language>remote keys in common case; this array allocated ahead</technical_language>

Target:
private <C extends WriteCommand, Container, Item> void handleLocalSegmentsForReadWriteManyCommand( InvocationContext ctx, C command, WriteManyCommandHelper<C, Container, Item> helper, ConsistentHash ch, MergingCompletableFuture<Object> allFuture, MutableInt offset, IntSet segments) throws Exception { Container myItems = helper.newContainer(); List<Object> remoteKeys = null; for (Item item : helper.getItems(command)) { Object key = helper.item2key(item); if (segments.contains(keyPartitioner.getSegment(key))) { helper.accumulate(myItems, item); CacheEntry cacheEntry = ctx.lookupEntry(key); if (cacheEntry == null) { if (command.hasAnyFlag(FlagBitSets.SKIP_REMOTE_LOOKUP | FlagBitSets.CACHE_MODE_LOCAL)) { entryFactory.wrapExternalEntry(ctx, key, null, false, true); } else { if (remoteKeys == null) { remoteKeys = new ArrayList<>(); } remoteKeys.add(key); } } } } CompletionStage<Void> retrievals = remoteKeys != null ? remoteGetMany(ctx, command, remoteKeys) : null; int size = helper.containerSize(myItems); if (size == 0) { allFuture.countDown(); return; } final int myOffset = offset.value; offset.value += size; C localCommand = helper.copyForLocal(command, myItems); localCommand.setTopologyId(command.getTopologyId()); InvocationFinallyAction handler = createLocalInvocationHandler(ch, allFuture, segments, helper, MergingCompletableFuture.moveListItemsToFuture(myOffset)); if (retrievals == null) { invokeNextAndFinally(ctx, localCommand, handler); } else { Object result = asyncInvokeNext(ctx, command, retrievals); makeStage(result).andFinally(ctx, command, handler); } }