Source:
<code>private CompletableFuture<Void> executeInternal(boolean skipIndex) { if (lock.lock()) { List<CompletableFuture<Void>> futures = new ArrayList<>(); Deque<IndexedTypeIdentifier> toFlush = new LinkedList<>(); BiConsumer<Void, Throwable> flushIfNeeded = (v, t) -> { try { indexUpdater.flush(toFlush); } finally { lock.unlock(); } }; <START> CompletableFuture<Void> compositeFuture; <END> Map<MassIndexStrategy, Set<IndexedTypeIdentifier>> strategyPerType = new HashMap<>(); for (IndexedTypeIdentifier indexedType : searchIntegrator.getIndexBindings().keySet()) { MassIndexStrategy strategy = calculateStrategy(indexInspector, indexedType); strategyPerType.computeIfAbsent(strategy, s -> new HashSet<>()).add(indexedType); } try { strategyPerType.forEach((strategy, indexedTypes) -> { boolean workerClean = true, workerFlush = true; if (strategy.getCleanStrategy() == CleanExecutionMode.ONCE_BEFORE) { indexUpdater.purge(indexedTypes); workerClean = false; } if (strategy.getFlushStrategy() == FlushExecutionMode.ONCE_AFTER) { toFlush.addAll(indexedTypes); workerFlush = false; } IndexWorker indexWork = new IndexWorker(cache.getName(), indexedTypes, workerFlush, workerClean, skipIndex, strategy.getIndexingStrategy() == IndexingExecutionMode.PRIMARY_OWNER, null); futures.add(executor.submitConsumer(indexWork, TRI_CONSUMER)); }); compositeFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); return compositeFuture.whenCompleteAsync(flushIfNeeded, localExecutor); } catch (Throwable t) { lock.unlock(); return CompletableFutures.completedExceptionFuture(t); } } else { return CompletableFutures.completedExceptionFuture(new MassIndexerAlreadyStartedException()); } }</code><technical_language>This compositeFuture declared is used</technical_language>

Target:
private CompletableFuture<Void> executeInternal(boolean skipIndex) { if (lock.lock()) { List<CompletableFuture<Void>> futures = new ArrayList<>(); Deque<IndexedTypeIdentifier> toFlush = new LinkedList<>(); BiConsumer<Void, Throwable> flushIfNeeded = (v, t) -> { try { indexUpdater.flush(toFlush); } finally { lock.unlock(); } }; Map<MassIndexStrategy, Set<IndexedTypeIdentifier>> strategyPerType = new HashMap<>(); for (IndexedTypeIdentifier indexedType : searchIntegrator.getIndexBindings().keySet()) { MassIndexStrategy strategy = calculateStrategy(indexInspector, indexedType); strategyPerType.computeIfAbsent(strategy, s -> new HashSet<>()).add(indexedType); } try { strategyPerType.forEach((strategy, indexedTypes) -> { boolean workerClean = true, workerFlush = true; if (strategy.getCleanStrategy() == CleanExecutionMode.ONCE_BEFORE) { indexUpdater.purge(indexedTypes); workerClean = false; } if (strategy.getFlushStrategy() == FlushExecutionMode.ONCE_AFTER) { toFlush.addAll(indexedTypes); workerFlush = false; } IndexWorker indexWork = new IndexWorker(cache.getName(), indexedTypes, workerFlush, workerClean, skipIndex, strategy.getIndexingStrategy() == IndexingExecutionMode.PRIMARY_OWNER, null); futures.add(executor.submitConsumer(indexWork, TRI_CONSUMER)); }); CompletableFuture<Void> compositeFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); return compositeFuture.whenCompleteAsync(flushIfNeeded, localExecutor); } catch (Throwable t) { lock.unlock(); return CompletableFutures.completedExceptionFuture(t); } } else { return CompletableFutures.completedExceptionFuture(new MassIndexerAlreadyStartedException()); } }