Skip to content

Commit 600e10c

Browse files
authored
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
1 parent 8c3d2e6 commit 600e10c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

cloud-annotations/src/main/java/org/incendo/cloud/annotations/suggestion/MethodSuggestionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public MethodSuggestionProvider(
8787
@SuppressWarnings("rawtypes")
8888
public static @NonNull CompletableFuture<Iterable<@NonNull Suggestion>> mapSuggestions(final @NonNull Object input) {
8989
if (input instanceof CompletableFuture) {
90-
return mapSuggestions((CompletableFuture) input);
90+
return mapFuture((CompletableFuture) input);
9191
}
9292
return CompletableFuture.completedFuture(mapCompleted(input));
9393
}

cloud-annotations/src/test/java/org/incendo/cloud/annotations/feature/MethodSuggestionProviderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Collections;
2727
import java.util.List;
2828
import java.util.Set;
29+
import java.util.concurrent.CompletableFuture;
2930
import java.util.stream.Stream;
3031
import org.checkerframework.checker.nullness.qual.NonNull;
3132
import org.incendo.cloud.CommandManager;
@@ -94,6 +95,7 @@ void testSuggestions(final @NonNull Object instance) {
9495
named("set source", new TestClassSet()),
9596
named("stream source", new TestClassStream()),
9697
named("iterable source", new TestClassIterable()),
98+
named("list future source", new TestClassFutureList()),
9799
named("string list source", new TestClassListString()),
98100
named("source with CommandInput injected", new TestClassCommandInput()),
99101
named("source with injected value", new TestInjectedValue())
@@ -156,6 +158,17 @@ public static final class TestClassListString {
156158
}
157159
}
158160

161+
public static final class TestClassFutureList {
162+
163+
@Suggestions("suggestions")
164+
public @NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestions(
165+
final @NonNull CommandContext<TestCommandSender> context,
166+
final @NonNull String input
167+
) {
168+
return CompletableFuture.completedFuture(Collections.singletonList(Suggestion.suggestion("foo")));
169+
}
170+
}
171+
159172
public static final class TestClassCommandInput {
160173

161174
@Suggestions("suggestions")

0 commit comments

Comments
 (0)