Confusing new code issue

  • Enterprise Edition
  • Version 8.9 (build 43852)

I have a failing quality gate for new code on a given project that SQ is reporting as having happened in the new code period, but when looking at the time stamp on the margin for the issue that is raised, it does not appear to be new code. Here’s some pictures to show you what I mean. See below that it indicates the issue occurred 17 days ago which is indeed in our new code period for this project. Notice that it is not backed in yellow like new code typically is.

Here’s the dropdown showing the date:

However, if I click the margin to see the git date, you will see the following:

See the date there is from 5 years ago. Why is this being flagged by my new code quality gate? I also checked the date of the rule and it says it has been around since May of 2020. We did recently update to 8.9 LTS but if that rule has been around for that long I can’t see how that could be the reason.

Thanks for the help.

Tom Z

Hi Tom,

This is most often caused by changes in other parts of the code. Without access to the history of this file, it’s difficult for me to identify exactly what type of change would have triggered this. At a guess, code that was previously blocking this issue was deleted. Another guess is that the quality of your analysis improved; i.e. dependencies that weren’t previously available to analysis because available 17 days ago, allowing the rule to take a “smarter” look at the code.

 
Ann

@ganncamp,

Let me reply back my understanding to be sure I have it. Code that has not been edited within the new code period, may be treated as new if it is dependent upon code that has changed.

For example, say I have an if/else clause and I edit the conditional expression in the if statement, then the body of the if/else, which is dependent upon the conditional expression, may be treated as new?

For example:

// suppose this next line changed by adding state == complete in the new code period
if (state == complete || TRUE == exit) { 
    // are you saying this next line may be treated as new, even if it has not changed?
    terminate_and_exit(); 
} else {
    // are you saying this next line may be treated as new, even if it has not changed?
    continue_processing(); 
}

`

Hi,

Not quite. As you noted, the code is not highlighted yellow to indicate that it is new. But the issue that was raised on it was seen for the first time 17 days ago. So the issue is new. It’s a new issue on old code.

For example let’s say this is the original state:

1  // All good. No NPEs here.
2  if (name != null) {
3    System.out.println(name);
4  }

And then it’s edited to this:

1  // New issue on old code
2  //if (name != null) {
3    System.out.println(name);
4  //}

Line 3 has not been edited. It’s date is still 5 years old. And yet a brand new NPE issue is raised on it.

 
HTH,
Ann