Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现NPE风险 #59

Open
xiuji666 opened this issue Dec 6, 2022 · 1 comment
Open

发现NPE风险 #59

xiuji666 opened this issue Dec 6, 2022 · 1 comment

Comments

@xiuji666
Copy link

xiuji666 commented Dec 6, 2022

您好,我正在用蚂蚁的单元测试用例自动生成工具(https://github.com/TRaaSStack/auto-unit-test-case-generator)
对这个项目进行测试,发现如下两个可能引发NPE的问题,期待得到您的反馈。
一 HotTagCache类中可能抛出NPE
被测方法的入参为Map,在其中一个添加的元素的value赋null值
image
被测方法:
image
image

源码中在遍历元素的时候,由于其中的一个元素的value值为空,而代码中未对null做非空校验,导致在进入compareTo的时候,this.getPriority()获取的值为null,从而报npe异常

二 UserStrategyFactory类中可能抛出NPE
调用被测方法之前,先对被测类的私有属性类型为list的strategies赋初值,即在list中添加null元素
image
被测方法:
image
在被测方法中,遍历list时,未对元素strategy做非空判断,导致strategy.getSupportedType()操作时报npe

@whatbugsyou
Copy link

UserStrategyFactory中属性strategies被@Autowired修饰,strategies的初始化归spring管理,所以list中不会出现null对象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants