Qube version: Community Build v25.7.0.110598
There are two rules for the Java Deprecated annotation, that kind of work together:
S6355: Complains about a naked @Deprecated annotation without any arguments.
S1133: Reminds me to remove code marked with @Deprecated.
If I have both activated in my profile and always follow the @Deprecated rules, I will have no naked @Deprecated annotations anywhere. Yes, 6355 does not necessarily force me to add ‘forRemoval’. Without the attribute it defaults to forRemoval=false, which is kind of weird.
So, if I have annotated a method with @Deprecated(forRemoval=true), 1133 lists it to remind me to remove it. That’s fine.
BUT, if I have annotated code with @Deprecated(forRemoval=false), still 1133 lists it to remind me to remove it. This doesn’t look right as I have explicitly marked it, that I do NOT intend to remove it. Yes, I do have reasons to mark it deprecated, but don’t want to remove it (in the near future).
I think, 6355 is almost fine. It just does not make much sense to accept @Deprecated with only one of ‘since’ and ‘forRemoval’. It should force ‘forRemoval’ to be used. ‘since’ is indeed optional. Yes, ‘forRemoval’ has a default. Though this default doesn’t really reflect what the annotation said before there were any attributes. And what is this rule good for then?
1133 is perfectly fine, if code is explicitly marked forRemoval=true. A reminder to remove the code is nice.
But 1133 also looks outdated maybe. It doesn’t reflect the new attribute ‘forRemoval’. I’m not sure, if it should rely on the default forRemoval=false, because I don’t think, if code is explicitly marked not to be removed, it is the same as if I haven’t thought about it (no attribute).
I think, 1133 should only list a finding, if there is no ‘forRemoval’ attribute or if it is true. Or, if you consider the current implementation fine, I suggest three new rules: One, that lists code to be removed, if ‘forRemoval’ is missing, one for forRemoval=false and one, that lists it, if forRemoval=true. Another solution could be to make 1133 configurable, so that it only lists findings if {forRemoval is missing; forRemoval=false or missing; forRemoval=false/true or missing}.
What do you think?