FP Javabugs S6651 Conditionally executed code should be reachable

  • What language is this for? Java
  • Which rule? S6651
  • SonarQube Eneterprise v10.8.1

This is a multi-threaded environment and ‘cached’ can be modified by a different thread between the two ‘if’ statements. That is the reason for the synchronization on the 2nd if.

Please no comments on the underlying functionality. The code is reachable so this is a FP.

if (!cached) { return this; }
     synchronized (this)
        {
            if (!cached) { return this; }
            cached = false;
            return this;
        }

Hey Kevin.

In order to help us reproduce the issue, it would be great if you could provide a complete, compilable code sample.

When we have to fill in the blanks on what’s missing, it tends to get messy fast.

Since S6551 is not supported in the IDE, only in the Server I cannot generate the warning in the IDE so cannot provide a complete, compilable code sample. I think the sample I provided along with the description should be sufficient for the developer.

A complete, compilable code sample can (and should) still raise an issue in SonarQube Server!

This is a community forum, we expect that users put in their 50% so that we can be effective and efficient when asking developers to spend their time looking at an issue.

Otherwise, you can mark the issue as false-positive and we’ll wait for a report with more details. We’d prefer not to do that.

Yes, I agree a code sample can still raise the issue on SonarQube Server but in our environment I don’t have the ability to submit a code sample to be executed on our SonarQube Server, I can only do it in my IDE which does not support the specified rule. So I guess you’ll need to wait for another report.