Mismatch of code reports between master and pull request analysis

SonarQube version: 2025.3

Recently, our dev team highlighted that they have observed the mismatch of code at master reports (wrong results or old issues are highlighted) after the consideration of the pull request analysis reports of feature branch and merge it into master. How we can fix this behavior.

Hi,

Welcome to the community and thanks for this report!

I don’t understand what’s going wrong here. Can you provide more detail? Perhaps with screenshots, redacted as necessary?

 
Thx,
Ann

Hi Anna,

We have project which is having a pull request analysis decoration enabled (Jenkins).

Developers reported that they are facing challenges like the scan results are not correct from the pull request analysis of the project . Once ,the feature branch code is pushed to master by referring the pull request analysis results ,they have observed inaccurate results in Master code scan such as code smells which are not reported in pull request scan and reporting once old issues once merged into master .

Thanks

Hi,

Again, you haven’t provided much to go on here.

For this, it’s quite possible it’s legitimate. In PR analysis, we only report issues raised on changed lines. But a change in one line could cause new issues in an unchanged line. I would need more details to give you a more precise answer.

 
Ann

Hi Ann,

Thanks for your previous response . I came up with below observations from our dev teams.

One inconsistency we observed during the Sonarqube scan is explained below:

“A java class in our project , previously imported Joda-Time(joda-time-2.9.9.jar) library, and the application was using the (org.joda.time.DateTime) class . During refactoring , we transitioned to a different date-time library . however , the developer who updated the code forgot to remove the unused import statement of Joda-Time(Import org.joda.time.DateTime). As a result, the class file was committed with this unused import still present. When the branch build was scanned (Pull-request decoration ), Sonarqube did not report any code smells. However, during the master branch scan, Sonarqube flagged this as a code smell , Which is rightly identifying the unused import import in the class which is not reporting the when we scan the branch in sonarqube.”

Please let me know if you are looking for any further details.

Hi,

Thanks for this context. This is actually a classic example of which issues are not raised in a pull request context. For PRs we only report issues raised on changed code. That old, now-unused import was not changed and therefore no issue was raised. Unfortunately, this is a known issue - one we’ve stubbed our toes on internally as well. But it’s not a simple one to fix.

 
HTH,
Ann