My team recently ran into an oddity with the Java Rule java:S1123
Deprecation should be marked with both the @ Deprecated annotation and @ deprecated Javadoc tag. The annotation enables tools such as IDEs to warn about referencing deprecated elements, and the tag can be used to explain when it was deprecated, why, and how references should be refactored.
In our case, we marked an existing method with @ Deprecated:
class MyClass {
@Deprecated // New line added and scanned by branch analysis, compliant in isolation
public void foo1() { // Existing method signature not scanned by branch analysis, now noncompliant
}
}
Our branch analysis is configured to compare against master (and gates merge to trunk based on SonarQube violations). The diff only showed the annotation and in isolation it was not a violation. However, a total analysis showed the violation because it scanned both the newly added annotation and the existing method signature. In other words, the method signature was existing code ignored by branch analysis and the annotation alone was not a violation but together they violate this rule.
The issue is that this rule violation is not detected by branch analysis because the violation is associated with the existing method signature and a branch analysis only detects new code. So adding the @ Deprecated annotation to a method will introduce a violation that cannot be caught by analyzing new code. Additionally, on the SonarQube dashboard the violation was backdated to when the existing method signature was added. For example, we added the method a year ago and adding the @ Deprecated annotation introduced a one year old violation.
The expected result here would be that adding @ Deprecated to a method would trigger this violation against the line containing the annotation. What do you think?
P.S. Love your product by the way. One of the best IntelliJ plugins IMO.
P.S.S. Had to add a space between “@” and “Deprecated” because it thought I was trying to @ someone.