Windows Eclipse using SonarLint plugin 7.9.0.66038 for java
Rule states it is not raised for booleans that have been null checked.
As can be seen in the following code ‘value’ has been null checked but rules is still raised.
if (value == null)
{
return "null";
}
try
{
type = metaData.getColumnType(column+1);
}
catch (SQLException e)
{
return value.toString();
}
switch(type)
{
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
return value.toString();
case Types.BIT:
return (Boolean)value ? "1" : "0";
case Types.DATE:
return value.toString(); // This will need some conversion.
default:
return "\""+value.toString()+"\"";
}
The problem is that the described exception from the rule: “not raised when already null-checked”, accounts only if it is the very same expression (value), while (Boolean) value is another expression. The current implementation of the rule does not perform a more sophisticated data flow analysis considering also the subexpressions of the expression.
Therefore, (Boolean) value accounts as “not null-checked” for the rule, even though value has been checked for null.