This method contains a redundant check for a known non-zero value against the constant null

javac 1.7.0_79
findbugs 3.0.0

      

Hello,

I am using findbugs and I am getting this reported error:

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

      

Code in questions:

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

      

The above code verifies that the mClientConnection contains a valid link.

The constructor contains the following:

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

      

I'm wondering how can I check that the mClientConnection contains a valid link?

Thanks a lot for any suggestions,

+3


source to share


1 answer


The reason you are getting this message from Findbugs is because the constructor will never return null

. So there is no reason to do a null check on mClientConnection

. If the constructor fails, the line of code that is used mClientConnection

will never be called.



+7


source







All Articles