Skip to main content

Command Palette

Search for a command to run...

SonarLint: Java - Null checks should not be used with "instanceof" (squid:S4201)

Updated
1 min read
SonarLint: Java - Null checks should not be used with "instanceof" (squid:S4201)
S

I love learning about technology and sharing that with others

Null check should not be used with the instance of since it is redundant, there is no need to check the null with an instance of since null is not an instance of anything,

I think this makes sense

Non-Compliant Code

if((customFieldType!=null) && (customFieldType instanceof AttachmentCFType)){
                String mode = this.getMode();
            }

Compliant Solution

  • Removed the null check from the if block
if(customFieldType instanceof AttachmentCFType){
                String mode = this.getMode();
            }
8 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)