New code on branch OK, but once merged Not OK

Hi,

I’m on SonarQube 10.3 Community Edition.

I modified my Java source code and refactor one method (a few lines) : in this method refactoring, I deleted the unique usage of a static variable declared on top of my Java class.
When I commited on my branch, all was OK for SonarQube on this branch : no issue and coverage 100%.
The problem occured when I merged this branch to master branch : a major issue occured on this top static variable that is not used anymore.

I look into Sonarqube configuration after reading the “new code” documentation here https://docs.sonarsource.com/sonarqube/latest/project-administration/clean-as-you-code-settings/defining-new-code/
But for me, the problem is that the branch code is analyzed only on “new code” without checking impacts on the whole class.

What can I do to resolve this kind of problem ?
Thank you.

Regards.

Hi,

Unfortunately, this is a known issue, and one that’s been on our radar for a while with no easy solution.

 
Ann

Hi @ganncamp,
thank you for answer.

David.
regards.

hi @ganncamp,

I have a new use case for this problem.
I modified a private mothod to delete an usage of a specific class (present on import list at top of the file).
I created a PR on this modification and my pipeline was ok (no raised issues).

Next, I merged this branch and a new major issue was raised saying to me that I have an unsued import.

regards

Hi,

Yes, this is essentially the same case as the previous one (modification causes new issue in old code).

 
Ann

1 Like

Hi,

thank you @ganncamp !

have a good day.

regards.

David