Code duplication quality gate: only Javadoc changes - what are best practices?

  • SonarQube Developer Edition 7.7
  • SonarJava 5.13.1 (build 18282)

A branch has over 10% code duplication on new code, which has triggered a quality gate to fail. We have a rather low % on code duplication on new code, because usually our developers are actually getting better all the time at writing good code.

The only changes in this particular branch, were improvements on Javadocs. No “actual code” changes.

On closer inspection, it turns out to be that 2 files have 100% duplication on new code.
On even closer inspection, it turns out that in both files, the new lines are 2 Javadoc lines that have been added, and those two lines are identical to 2 Javadoc lines in another class.

My questions:

  • Is it expected to have “code duplication” detection on comments, not code?
  • How do other companies and development teams deal with a situation like this? What are best practices?

Some ideas I already have, without making any changes to the code:

  • Combine this branch with another branch, so that “numerically” the code duplication % is below the quality gate.
  • Raise the quality gate to let this code duplication pass

Looks like my question is a duplicate of Ignore Duplications within Javadoc, unfortunately that never got a solution.
In any case, this already answers my first question: code duplication detection on Javadoc comments is unexpected.

Which raises a new question: how did that happen in the first place and how to get rid of it?

Here’s a screenshot of the duplicated code:

While the surrounding code is indeed also detected as duplicated, that is existing code from 2017, and is not relevant for this particular issue.
We’re only talking about the 2 Javadoc lines added by user dima, lines 478-479.