mirror of
https://github.com/aikar/commands.git
synced 2026-06-11 10:30:38 +00:00
Don't allow infinite recursive annotations (#258)
This commit is contained in:
@@ -27,6 +27,8 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -50,7 +52,7 @@ class Annotations <M extends CommandManager> extends AnnotationLookups {
|
||||
}
|
||||
|
||||
String getAnnotationValue(AnnotatedElement object, Class<? extends Annotation> annoClass, int options) {
|
||||
Annotation annotation = getAnnotationRecursive(object, annoClass);
|
||||
Annotation annotation = getAnnotationRecursive(object, annoClass, new HashSet<>());
|
||||
String value = null;
|
||||
|
||||
if (annotation != null) {
|
||||
@@ -103,13 +105,15 @@ class Annotations <M extends CommandManager> extends AnnotationLookups {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Annotation getAnnotationRecursive(AnnotatedElement object, Class<? extends Annotation> annoClass) {
|
||||
private static Annotation getAnnotationRecursive(AnnotatedElement object, Class<? extends Annotation> annoClass, Collection<Annotation> checked) {
|
||||
if (object.isAnnotationPresent(annoClass)) {
|
||||
return object.getAnnotation(annoClass);
|
||||
} else {
|
||||
for (Annotation otherAnnotation : object.getDeclaredAnnotations()) {
|
||||
if (!otherAnnotation.annotationType().getPackage().getName().startsWith("java.")) {
|
||||
final Annotation foundAnnotation = getAnnotationRecursive(otherAnnotation.annotationType(), annoClass);
|
||||
if (checked.contains(otherAnnotation)) return null;
|
||||
checked.add(otherAnnotation);
|
||||
final Annotation foundAnnotation = getAnnotationRecursive(otherAnnotation.annotationType(), annoClass, checked);
|
||||
if (foundAnnotation != null) {
|
||||
return foundAnnotation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user