mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
!975 修复使用AnnotationUtil.getAnnotationAlias获取注解时可能会出现空指针的问题
Merge pull request !975 from Sparks/v5-dev
This commit is contained in:
commit
6f68e2fac7
@ -457,6 +457,9 @@ public class AnnotationUtil {
|
||||
*/
|
||||
public static <T extends Annotation> T getAnnotationAlias(AnnotatedElement annotationEle, Class<T> annotationType) {
|
||||
final T annotation = getAnnotation(annotationEle, annotationType);
|
||||
if (null == annotation) {
|
||||
return null;
|
||||
}
|
||||
return aggregatingFromAnnotation(annotation).synthesize(annotationType);
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,14 @@ public class AnnotationUtilTest {
|
||||
Assert.assertTrue(AnnotationUtil.isSynthesizedAnnotation(annotation));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAnnotationSyncAliasWhenNotAnnotation() {
|
||||
getAnnotationSyncAlias();
|
||||
// 使用AnnotationUtil.getAnnotationAlias获取对象上并不存在的注解
|
||||
final Alias alias = AnnotationUtil.getAnnotationAlias(ClassWithAnnotation.class, Alias.class);
|
||||
Assert.assertNull(alias);
|
||||
}
|
||||
|
||||
@AnnotationForTest(value = "测试", names = {"测试1", "测试2"})
|
||||
@RepeatAnnotationForTest
|
||||
static class ClassWithAnnotation{
|
||||
|
Loading…
x
Reference in New Issue
Block a user