Is there a rule to scan null pointer exceptions?(Java)

This is the result of my search

Product product = new Product();
String string = product.getDeviceTypeId().toString();//A “null point Exception” may be thrown here,Can sonar scan it out?

Hi,

yes, with the rule ‘Null pointers should not be dereferenced’ / java:S2259
see SonarSource Code Analyzers Rules Explorer
and the Noncompliant Code Example

Gilbert

1 Like