diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7c5c72f..fc6026215 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ * 【socket 】 修复异常socket没有关闭问题(pr#690@Gitee) * 【core 】 修复当时间戳为Integer时时间转换问题(pr#2449@Github) * 【core 】 修复bmp文件判断问题(issue#I5H93G@Gitee) +* 【core 】 修复CombinationAnnotationElement造成递归循环(issue#I5FQGW@Gitee) ------------------------------------------------------------------------------------------------------------- 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 e2e901d66..fd4800a0a 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 @@ -1,19 +1,13 @@ package cn.hutool.core.annotation; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.TableMap; import java.io.Serializable; import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; import java.lang.reflect.AnnotatedElement; import java.util.Arrays; import java.util.Collection; import java.util.Map; -import java.util.Set; import java.util.function.Predicate; /** @@ -126,7 +120,9 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa // 直接注解 for (Annotation annotation : annotations) { annotationType = annotation.annotationType(); - if (AnnotationUtil.isNotJdkMateAnnotation(annotationType)) { + // 跳过元注解和已经处理过的注解,防止递归调用 + if (AnnotationUtil.isNotJdkMateAnnotation(annotationType) + && false == declaredAnnotationMap.containsKey(annotationType)) { if(test(annotation)){ declaredAnnotationMap.put(annotationType, annotation); } @@ -145,7 +141,8 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa Class annotationType; for (Annotation annotation : annotations) { annotationType = annotation.annotationType(); - if (AnnotationUtil.isNotJdkMateAnnotation(annotationType)) { + if (AnnotationUtil.isNotJdkMateAnnotation(annotationType) + && 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 17407fbf5..19d920973 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 @@ -16,14 +16,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()); }