# Java annotations reported as code duplicate

**URL:** <https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020>\
**Category:** Report False-positive / False-negative...\
**Tags:** duplications, sonarqube, java\
**Created:** [October 7, 2021, 6:53am UTC](https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020 "2021-10-07T06:53:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![svermeille](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/svermeille/32/2292_2.png) [@svermeille](https://community.sonarsource.com/u/svermeille)\
**Post date:** [October 7, 2021, 6:53am UTC](https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020/1 "2021-10-07T06:53:15Z")

</div>

- versions used (SonarQube 9.1.0.47736, Scanner LTS, language analyzer JAVA)

Hi, I have some false positive with sonarqube and JAVA analyzer.

In order to improve our swagger generated documentation (based on java annotations) we had to annotate multiple endpoints with such annotations:

```java
  @Operation(summary = "Do something")
  @ApiResponse(responseCode = "200", description = "Successfull")
  @ApiResponse(responseCode = "400", description = "Unable to do error")
  @ApiResponse(responseCode = "403", description = "Not Enough Permissions")
  @ApiResponse(responseCode = "404", description = "whatever not found")

```

Sonarqube report it as code duplicate.

Is there a way to tell sonarqube to not report duplication on annotations ?

I mean it’s a real problem. It is not really acceptable to have to manually approve all these things in our usage of sonarqube. This prevent us to merge pull requests as we really like to use sonarqube as a guardian in our code. And if a sonarqube admin have to come always to approve false positive like that… will be a night mare.

Any help will be very appreciated 🙂 thank you in advance

---

<div class="post-metadata">

**Author:** ![alban.auzeill](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alban.auzeill/32/36_2.png) [@alban.auzeill](https://community.sonarsource.com/u/alban.auzeill)\
**Post date:** [October 13, 2021, 5:03pm UTC](https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020/3 "2021-10-13T17:03:31Z")

</div>

Hi @svermeille,

There’s no way in SonarQube to ignore duplication on Java annotations.  
Perhaps you can create your own meta-annotation `public @interface MyDefaultApiResponse` that aggregates annotations that you always duplicate. I saw this kind of solution in discussions about “`How to avoid repeating yourself with Swagger annotations?`” like here:

> <https://stackoverflow.com/questions/48634417/how-to-dry-when-using-swagger-ui-and-the-apiresponses-annotations-with-java-spri>

Good luck,  
Alban

---

<div class="post-metadata">

**Author:** ![svermeille](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/svermeille/32/2292_2.png) [@svermeille](https://community.sonarsource.com/u/svermeille)\
**Post date:** [October 20, 2021, 8:28am UTC](https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020/5 "2021-10-20T08:28:33Z")

</div>

Thank you @alban.auzeill , it seems to be a good workaround for these issues.

Have a good day

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/78532_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [October 27, 2021, 8:29am UTC](https://community.sonarsource.com/t/java-annotations-reported-as-code-duplicate/51020/6 "2021-10-27T08:29:07Z")

</div>

Closed on October 27, 2021, 8:29am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
