Java – this method contains redundancy checks for known non null values of the constant null

javac 1.7.0_79
javac 1.7.0_79
findbugs 3.0.0

Hello,

I am using findbugs and I received this report with an error:

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

The code in the problem is as follows:

mClientConnection = new XMPPTCPConnection(configBuilder.build());
 if(mClientConnection == null) {
    return false;
 }

The above code checks whether the mclientconnection contains a valid reference

The constructor contains:

public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
    super(config);
    this.config = config;
}

I wonder how to check if mclientconnection contains valid references?

Thank you very much for any suggestions,

Solution

The reason you get this message from findbugs is because the constructor will never return null Therefore, you have no reason to null check mclientconnection If the constructor fails, the code line using mclientconnection will never be called

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>