From 600e10c4eeb0e79ad948421f7a8e15a168bb8c20 Mon Sep 17 00:00:00 2001 From: Emily Date: Wed, 11 Sep 2024 00:19:16 -0300 Subject: [PATCH] Fix infinite recursion when a `@Suggestions` method returns a `CompletableFuture` (#771) * Fix infinite recursion when a `@Suggestions` method returns a CompletableFuture * Name future test suggestion source more properly --- .../suggestion/MethodSuggestionProvider.java | 2 +- .../feature/MethodSuggestionProviderTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cloud-annotations/src/main/java/org/incendo/cloud/annotations/suggestion/MethodSuggestionProvider.java b/cloud-annotations/src/main/java/org/incendo/cloud/annotations/suggestion/MethodSuggestionProvider.java index e34139554..a626d6611 100644 --- a/cloud-annotations/src/main/java/org/incendo/cloud/annotations/suggestion/MethodSuggestionProvider.java +++ b/cloud-annotations/src/main/java/org/incendo/cloud/annotations/suggestion/MethodSuggestionProvider.java @@ -87,7 +87,7 @@ public MethodSuggestionProvider( @SuppressWarnings("rawtypes") public static @NonNull CompletableFuture> mapSuggestions(final @NonNull Object input) { if (input instanceof CompletableFuture) { - return mapSuggestions((CompletableFuture) input); + return mapFuture((CompletableFuture) input); } return CompletableFuture.completedFuture(mapCompleted(input)); } diff --git a/cloud-annotations/src/test/java/org/incendo/cloud/annotations/feature/MethodSuggestionProviderTest.java b/cloud-annotations/src/test/java/org/incendo/cloud/annotations/feature/MethodSuggestionProviderTest.java index 3788af0fb..3e9fea28e 100644 --- a/cloud-annotations/src/test/java/org/incendo/cloud/annotations/feature/MethodSuggestionProviderTest.java +++ b/cloud-annotations/src/test/java/org/incendo/cloud/annotations/feature/MethodSuggestionProviderTest.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.CommandManager; @@ -94,6 +95,7 @@ void testSuggestions(final @NonNull Object instance) { named("set source", new TestClassSet()), named("stream source", new TestClassStream()), named("iterable source", new TestClassIterable()), + named("list future source", new TestClassFutureList()), named("string list source", new TestClassListString()), named("source with CommandInput injected", new TestClassCommandInput()), named("source with injected value", new TestInjectedValue()) @@ -156,6 +158,17 @@ public static final class TestClassListString { } } + public static final class TestClassFutureList { + + @Suggestions("suggestions") + public @NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestions( + final @NonNull CommandContext context, + final @NonNull String input + ) { + return CompletableFuture.completedFuture(Collections.singletonList(Suggestion.suggestion("foo"))); + } + } + public static final class TestClassCommandInput { @Suggestions("suggestions")