Skip to content

Commit

Permalink
Fix infinite recursion when a @Suggestions method returns a `Comple…
Browse files Browse the repository at this point in the history
…tableFuture` (#771)

* Fix infinite recursion when a `@Suggestions` method returns a CompletableFuture

* Name future test suggestion source more properly
  • Loading branch information
emilyy-dev authored Sep 11, 2024
1 parent 8c3d2e6 commit 600e10c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public MethodSuggestionProvider(
@SuppressWarnings("rawtypes")
public static @NonNull CompletableFuture<Iterable<@NonNull Suggestion>> mapSuggestions(final @NonNull Object input) {
if (input instanceof CompletableFuture) {
return mapSuggestions((CompletableFuture) input);
return mapFuture((CompletableFuture) input);
}
return CompletableFuture.completedFuture(mapCompleted(input));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<TestCommandSender> context,
final @NonNull String input
) {
return CompletableFuture.completedFuture(Collections.singletonList(Suggestion.suggestion("foo")));
}
}

public static final class TestClassCommandInput {

@Suggestions("suggestions")
Expand Down

0 comments on commit 600e10c

Please sign in to comment.