Make sure to read this post before raising a thread here:
Then tell us:
- What language is this for?
- Java
- Which rule?
- Duplicate code
- Why do you believe it’s a false-positive/false-negative?
- My problem was a false positive, but the solution I found might be a false negative in legitimate duplications
- Why it was a false positive:
- I have two database entity classes (javax.persistence)
- I use Lombok for creating getters and setters and there are no other methods inside. Only the column mappings.
- One of these entities represents a table and the other one represents a view.
- The view has a set of 6 columns with same names as the table
- This isn’t a duplication of code. They serve different purposes and this sort of block can’t be reused easily like that. It would even become confusing code if trying to do so
- Why I think the solution might cause a false negative:
- What I did to fix the issue was to scramble the order of these fields in the entity and it worked. The code is still “technically duplicated”, just in a different order, but SonarQube doesn’t complain about it anymore.
- Are you using
- SonarCloud?
- No
- SonarQube - which version?
- Yes, 9.8
- SonarLint - which IDE/version?
- Yes v7.3.0.59206, on IntelliJ Ultimate v2022.3.1
- in connected mode with SonarQube or SonarCloud?
- Yes, connected to the project through SonarQube, but SonarLint didn’t complain about the duplication. Only SonarQube.
- SonarCloud?
- How can we reproduce the problem? Give us a self-contained snippet (best) or screenshot (good)
- I guess, just have two pojo classes with a bunch of duplicate fields in the same order. This should be a true positive. But if you add the
@Entity
and@Table
there and@Table
in both have different parameters, then it would be a false positive. Scramble the fields in the pojo without the annotations and it should still call the duplication, though in my point of view. but it seems it doesn’t.
- I guess, just have two pojo classes with a bunch of duplicate fields in the same order. This should be a true positive. But if you add the