CompletableFuture<XDebuggerTreeNode> () { CompletableFuture<XDebuggerTreeNode> loaded = myLoaded; // a copy ref for the lambda in thenCompose() return myTreeRestorer != null ? CompletableFuture.allOf(myTreeRestorer.onFinished(), loaded).thenCompose(v -> loaded) : loaded.copy(); }