It's possible analyze issues in Java files with javax.annotation.Generated?

Hi,
Can I see issues in java files with the annotation javax.annotation.Generated?

I have tried to analyse a java file with the Generated annotation, but SonarQube don’t display a issue (code smell) that the file contains.

I have seen in the official documentation, that there are a way to exclude the issues in files with @Generated:
https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/

Ignore Issues

You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Administration > General Settings > Analysis Scope > Issues .

Note that the properties below can only be set through the web interface because they are multi-valued.

Ignore Issues on Files

You can ignore all issues on files that contain a block of code matching a given regular expression.

Example:

  • Ignore all issues in files containing “javax.annotation.Generated”
    javax\.annotation\.Generated

For this, I can understand that, if I leave blank the field “Ignore issues on files”, SonarQube should show the issues of the java files allthough it has @Generated annotations.

I have realized the test with a SonarQube 7.9.1 instance

It’s a bug?
or
There are no way to show issues of java.annotation.Generated code?

Thanks
Kind regards

Where is the source folder of those generated files?

Hi,
is in /src/main/java.

Hello Oscar,

To answer your question, no, it is not possible to analyse generated file marked with @Generated annotation.

The rational behind this feature is that for a huge majority of cases, these files will just make noise to your analysis. You do not expect developers to modify such file (any modification is going to be erased at the next generation), and therefore you don’t want them to impact your quality gates. If you are not a maintainer of the generator, it will also be painful to follow.

If you want to be sure of the quality of such generated code, I would recommend to simply (temporarily?) drop the annotation, identify fishy code, fix the generator, and add back the annotation.

Hope this helps,
Michael

Hi Michael,
thanks to reply.

I’m agree with the behind of this feature, but i was confused reading the official documentation.

Thanks!
Kind regards