六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 68|回复: 0

2.Nullcheck of value previously dereferenced

[复制链接]

升级  66.67%

36

主题

36

主题

36

主题

秀才

Rank: 2

积分
150
 楼主| 发表于 2013-1-26 13:35:43 | 显示全部楼层 |阅读模式
[hyddd的FindBugs分析记录][M C RCN] Nullcheck of value previously dereferenced

[M C RCN] Nullcheck of value previously dereferenced [RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE]
A value is checked here to see whether it is null, but this value can't be null because it was previously dereferenced and if it were null a null pointer exception would have occurred at the earlier dereference. Essentially, this code and the previous dereference disagree as to whether this value is allowed to be null. Either the check is redundant or the previous dereference is erroneous.
 
先看一段代码:
<div class="cnblogs_code">public class MyTest {
     
    
private String str = "123";
    
public void setStr(String str){
        
this.str = str;
    }
    
public String getStr(){
        
return this.str;
    }

    
public void test(){
        String str2
= "123";
        
synchronized (str) {
            
if (str != null) {
                str2
="123";
            } 
else {
                str2
="456";
            }           
            System.out.println(str2);
        }
    }
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表