SonarQube Squid False Squid: S2583

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?

+4
source share
1

java 3.9

+3

Source: https://habr.com/ru/post/1624733/


All Articles