Note: the code here is just the minimal code to recreate, the code that caused this problem actually included the object InitialContext.
Squid rules SonarQube: S2583,
Modify this condition so that it does not always evaluate to true
seems to create false positives when creating the object, even if the constructor throws a checked exception. As a minimal example
public void falsePositive()
{
TestObject myValue = null;
try
{
myValue = new TestObject();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (myValue != null)
{
System.out.println("Not null");
}
}
}
C TestObjectdeclared as
public class TestObject
{
public TestObject() throws Exception
{
throw new Exception();
}
}
This creates a problem in the string if (myValue != null), implying that myValueit is not always null, which is obviously not the case.
Is this a mistake in the rule, or am I just missing something here?
source
share