# Sonarcloud Quality Gate failed for old code

**URL:** <https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189>\
**Category:** SonarQube Cloud\
**Tags:** sonarqube-cloud\
**Created:** [March 16, 2021, 5:10pm UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189 "2021-03-16T17:10:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tejas.shah](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tejas.shah](https://community.sonarsource.com/u/tejas.shah)\
**Post date:** [March 16, 2021, 5:10pm UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/1 "2021-03-16T17:10:16Z")

</div>

I’m using SonarCloud for Analyzing the Projects.  
The quality gate rules are default Sonar way.  
I have set new code definition as **Previous Version**

In one analysis, the analyzer reported bugs in older code(2 years older code) due to which the quality gate failed.

Why Sonar Quality gate is reporting bugs in older code even though quality gate rules are only for new code?

Regards,  
Tejas

---

<div class="post-metadata">

**Author:** ![Carine\_Bayon](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carine_bayon/32/3223_2.png) [@Carine\_Bayon](https://community.sonarsource.com/u/Carine_Bayon)\
**Post date:** [March 16, 2021, 6:04pm UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/2 "2021-03-16T18:04:39Z")

</div>

Hi @tejas.shah ,

can you share screenshots of your Quality Gate and of your project which failed?

Thanks,  
Carine

---

<div class="post-metadata">

**Author:** ![tejas.shah](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tejas.shah](https://community.sonarsource.com/u/tejas.shah)\
**Post date:** [March 17, 2021, 10:50am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/3 "2021-03-17T10:50:20Z")

</div>

Hi @Carine_Bayon ,

**Quality Gate and new code definition settings :**  
For new code definition we have set for Previous Version and the quality gate rules are copy of Sonar Way.

 ![SonarCloud Quality Gate](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/0/c/0ca2fb14527f013c083c218ffc7b5a20a78a23b8.png)

![new_code_definition](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/e/6e70a946bb3ba00bb92f0531ef055a6ae9c60c00.png)

**Failed Project :**  
The quality gate fails for Reliability Rating since it is reporting bugs in old code.

 ![sonar_oldCode_issue](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/2/5236eea1add6f93e66d7f0ab831caea81781a9b1.png)

Are we misconfiguring something ?

Regards,  
Tejas

---

<div class="post-metadata">

**Author:** ![Carine\_Bayon](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carine_bayon/32/3223_2.png) [@Carine\_Bayon](https://community.sonarsource.com/u/Carine_Bayon)\
**Post date:** [March 17, 2021, 11:05am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/4 "2021-03-17T11:05:21Z")

</div>

Can you add a screenshot of your project homepage please? (with the QG status and conditions failed) ?

Thanks,  
Carine

---

<div class="post-metadata">

**Author:** ![tejas.shah](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tejas.shah](https://community.sonarsource.com/u/tejas.shah)\
**Post date:** [March 17, 2021, 2:14pm UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/5 "2021-03-17T14:14:52Z")

</div>

The QG is failing for a **feature** branch due to multiple conditions. But seeing the **Reliability Rating** report, it has marked a **bug** in an older code.

![sonar_failed_QG](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/2/5/250ea85c0ba1b9991bf67b9ef147e7b74439183f.png)

![bugs_in_branch](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/a/ca5bf81dad55fc55ccd300ea0a10f8bea8fcb4cc.png)

Regards,  
Tejas

---

<div class="post-metadata">

**Author:** ![mickaelcaro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/mickaelcaro/32/4147_2.png) [@mickaelcaro](https://community.sonarsource.com/u/mickaelcaro)\
**Post date:** [March 18, 2021, 9:09am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/9 "2021-03-18T09:09:30Z")

</div>

Hi @tejas.shah

When was analyze you latest version ? What does show the activity tab of your base branch ?

Thanks.

---

<div class="post-metadata">

**Author:** ![tejas.shah](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tejas.shah](https://community.sonarsource.com/u/tejas.shah)\
**Post date:** [March 18, 2021, 11:17am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/10 "2021-03-18T11:17:22Z")

</div>

Hi @mickaelcaro , There is ongoing development process,  
so after every few hours there might be a new analysis version.  
Following is the activity tab of main branch (develop)

 ![sonar-activity](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/7/d7d41ca802f5f688efbfe64f3055f22a1e71ac52.png)

Regards,  
Tejas

---

<div class="post-metadata">

**Author:** ![mickaelcaro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/mickaelcaro/32/4147_2.png) [@mickaelcaro](https://community.sonarsource.com/u/mickaelcaro)\
**Post date:** [March 18, 2021, 12:34pm UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/11 "2021-03-18T12:34:31Z")

</div>

And before this today’s version, when was the previous one on develop ?

---

<div class="post-metadata">

**Author:** ![tejas.shah](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tejas.shah](https://community.sonarsource.com/u/tejas.shah)\
**Post date:** [March 19, 2021, 9:33am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/12 "2021-03-19T09:33:42Z")

</div>

This Project was on-boarded on SonarCloud on 3rd March, 2021. This is the first version that is on-boarded. Since then, this version hasn’t been changed.

Regards,  
Tejas

---

<div class="post-metadata">

**Author:** ![mickaelcaro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/mickaelcaro/32/4147_2.png) [@mickaelcaro](https://community.sonarsource.com/u/mickaelcaro)\
**Post date:** [March 19, 2021, 10:51am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/14 "2021-03-19T10:51:48Z")

</div>

Ok, so it looks like it’s normal : A baseline is established : since you’ve created a version, from now on, those issues will not appear again.

---

<div class="post-metadata">

**Author:** ![trejkaz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/trejkaz/32/355_2.png) [@trejkaz](https://community.sonarsource.com/u/trejkaz)\
**Post date:** [March 23, 2021, 2:21am UTC](https://community.sonarsource.com/t/sonarcloud-quality-gate-failed-for-old-code/40189/15 "2021-03-23T02:21:55Z")

</div>

This sounds like typical Sonar behaviour to me. If the code you start with is already failing, you’d better hope you never have to change it, not even to make improvements, because as soon as you try to make one improvement in the code, the quality gate will kick you in the balls for not fixing every other issue in the same area.

Some classic examples of this from recent memory:

1. I removed a warning suppression and Sonar failed the quality gate complaining about suppressing warnings.
2. I made a line of code shorter and Sonar quality gate complained about the line of code being too long.
3. I fixed the indenting on a line and Sonar quality gate complained about some existing issue that happened to have code on the same line.

I think Sonar is just not current designed in a way to encourage people to improve code quality because most of the time, when trying to do so, the quality gate prevents you making the change.

Rather than doing warning accounting on a line by line basis, it should be looking at the total warnings before and after and only complaining if the total went up.
