From 94d5889b1c02006ff5202e893525e2d3915b6753 Mon Sep 17 00:00:00 2001 From: Looly Date: Sun, 17 Jul 2022 18:43:58 +0800 Subject: [PATCH] fix bug --- .../core/annotation/CombinationAnnotationElement.java | 8 ++++++-- .../cn/hutool/core/annotation/AnnotationUtilTest.java | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/CombinationAnnotationElement.java b/hutool-core/src/main/java/cn/hutool/core/annotation/CombinationAnnotationElement.java index 062e7ac11..abbca341b 100755 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/CombinationAnnotationElement.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/CombinationAnnotationElement.java @@ -138,7 +138,9 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa // 直接注解 for (final Annotation annotation : annotations) { annotationType = annotation.annotationType(); - if (false == META_ANNOTATIONS.contains(annotationType)) { + if (false == META_ANNOTATIONS.contains(annotationType) + // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 + && false == declaredAnnotationMap.containsKey(annotationType)) { if(test(annotation)){ declaredAnnotationMap.put(annotationType, annotation); } @@ -157,7 +159,9 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa Class annotationType; for (final Annotation annotation : annotations) { annotationType = annotation.annotationType(); - if (false == META_ANNOTATIONS.contains(annotationType)) { + if (false == META_ANNOTATIONS.contains(annotationType) + // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 + && false == declaredAnnotationMap.containsKey(annotationType)) { if(test(annotation)){ annotationMap.put(annotationType, annotation); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java index 98d0dbe56..3032ed5ca 100755 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java @@ -11,14 +11,14 @@ public class AnnotationUtilTest { public void getCombinationAnnotationsTest(){ final Annotation[] annotations = AnnotationUtil.getAnnotations(ClassWithAnnotation.class, true); Assert.assertNotNull(annotations); - Assert.assertEquals(3, annotations.length); + Assert.assertEquals(2, annotations.length); } @Test public void getCombinationAnnotationsWithClassTest(){ final AnnotationForTest[] annotations = AnnotationUtil.getCombinationAnnotations(ClassWithAnnotation.class, AnnotationForTest.class); Assert.assertNotNull(annotations); - Assert.assertEquals(2, annotations.length); + Assert.assertEquals(1, annotations.length); Assert.assertEquals("测试", annotations[0].value()); }