Skip to content

May trigger a NullPointerException #87

@yomea

Description

@yomea

com.dao.cloud.starter.RpcProviderAutoConfiguration#onApplicationEvent中有一段这样的代码:

DaoService daoService = serviceBean.getClass().getAnnotation(DaoService.class);

Image

该代码获取 DaoService 时可能触发空指针异常!

触发点在 @daoservice 被修饰父类的时候,比如 接口 IA,它有一个实现 AImpl,这个实现类上标有 @daoservice 注解,但是最终
注册到spring中的类叫 BImpl ,这个 BImpl 继承了 AImpl ,BImpl 是被spring管理的,那么
DaoService daoService = serviceBean.getClass().getAnnotation(DaoService.class);
这段代码获取到的 DaoService是一个空对象,建议改成

AnnotatedElementUtils.findMergedAnnotation(serviceBean.getClass(), DaoService.class) 或 AnnotationUtils.findAnnotation(serviceBean.getClass(), DaoService.class);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions