[java:S1123] Suddenly new issues after targeting Java >= 9

This is not a false-positive per se, but rather a too strict rule.

The rule S1123 checks whether a method annotated with @Deprecated has a Javadoc tag @deprecated and vice versa. This is pretty useful because with only the annotation one would not know what the intended replacement for the method or class is.
With SonarJava 4.11 a change was made to the requiring one of the annotation attributes since or 'forRemoval` to be set when using Java >= 9.
This has one of the following implications:

  1. Existing code targeting Java >= 9 with methods/classes annotated/tagged as deprecated and conforming to the rule (with SonarJava < 4.11) is suddenly non-conformant after updating the rule
  2. Existing code targeting Java < 9 with methods/classes annotated/tagged as deprecated and conforming to the rule (with SonarJava >= 4.11) is suddenly non-conformant after targeting Java >= 9

This causes new issues and possibly more work. In my opinion, checking the annotation attributes should have been optional. Thus I kindly ask to either make the attribute check optional or to split this new feature into a separate rule.

Hello @oliver

To me, this problem can be addressed thanks to the Clean as You Code idea.
Existing issues are not the main focus (unless blocker), so news issues on old code do not really add more work. This rule will in fact make sure that new code written in Java 9 will respect the conventions.

Does it clarify the situation?

Hi @Quentin,

sorry for the long delay, I had to discuss with my colleagues first.

Like the rule says it is recommended as per Javadoc of the Deprecated annotation to include since and/or forRemoval. However, for us there is no additional benefit in using either attribute. The best solution for us is to write a custom rule which only checks that annotation and javadoc are both present.

Cheers,
Oliver

Hello @oliver

I agree with you, while both parts make sense individually, enforcing them together is not ideal. I suggest moving the second part of the logic to a new rule, it will allow you to fine-tune the behavior to suit your needs. See SONARJAVA-3864.

Thanks for raising this point, and have a nice day.
Quentin

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