From e241420ee96fd35a5207dc5c2758f7588ebedb40 Mon Sep 17 00:00:00 2001 From: jmp Date: Sun, 13 Dec 2020 01:42:27 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Throw=20an=20exception=20when=20try?= =?UTF-8?q?ing=20to=20parse=20a=20static=20method=20with=20the=20`@Command?= =?UTF-8?q?Method`=20annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commandframework/annotations/AnnotationParser.java | 7 +++++++ .../src/main/java/cloud/commandframework/Command.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java index 1e460631..1f02c75a 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java @@ -49,6 +49,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.Arrays; @@ -243,6 +244,12 @@ public final class AnnotationParser { method.getName() )); } + if (Modifier.isStatic(method.getModifiers())) { + throw new IllegalArgumentException(String.format( + "@CommandMethod annotated method '%s' is static! @CommandMethod annotated methods should not be static.", + method.getName() + )); + } commandMethodPairs.add(new CommandMethodPair(method, commandMethod)); } final Collection> commands = this.construct(instance, commandMethodPairs); diff --git a/cloud-core/src/main/java/cloud/commandframework/Command.java b/cloud-core/src/main/java/cloud/commandframework/Command.java index 35b7faf5..4d965ed8 100644 --- a/cloud-core/src/main/java/cloud/commandframework/Command.java +++ b/cloud-core/src/main/java/cloud/commandframework/Command.java @@ -639,7 +639,7 @@ public class Command { * Specify a required sender type * * @param senderType Required sender type - * @return New builder instance using the command execution handler + * @return New builder instance using the required sender type */ public @NonNull Builder senderType(final @NonNull Class senderType) { return new Builder<>(