Skip to content

发现NPE风险 #59

Description

@xiuji666

您好,我正在用蚂蚁的单元测试用例自动生成工具(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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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