[FindBugs分析记录]Redundant nullcheck of o

This method contains a redundant check of a known non-null value against the constant null.

  这种方法包含了一个称为非空对空值的不断重复检查。

什么代码会引起这个问题呢?先看下面:

复制代码

public static boolean isNull(Object o) {        if (null == o)            return null == o;        if (o instanceof String) {            return StringUtils.isBlank((String) o);
        }
        return o == null;
    }

复制代码

倒数第二行代码:return o == null;执行到这一步的时候已经表明o不为空,现在就是拿一个已知非空的值和null进行比较,findbus认为这是种运行期存在安全隐患的代码。

这里的建议是:防止这种情况出现,直接返回false.

复制代码

public static boolean isNull(Object o) {        if (null == o)            return null == o;        if (o instanceof String) {            return StringUtils.isBlank((String) o);
        }        return false;
    }

复制代码

转载于:https://my.oschina.net/lianghan/blog/345795

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值