Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube duplicated blocks of code between POJOs

Tags:

java

sonarqube

There are two POJOs Market and MarketDTO in two packages.

Market is a mapping object for JSON response from remote service.

MarketDTO is a response object which will be exposed via our service.

There are some data massage from Market->MarketDTO. They have some common fields and both have unique fields as well. There are 3 common fields such as id, name and status.

However, Sonarqube indicates their getters and setters as duplicated blocks of codes to be removed. Is this actually bad code or I should just mark it as false positive?

like image 602
MichaelYu Avatar asked Feb 05 '16 12:02

MichaelYu


People also ask

How to avoid duplicate code in SonarQube?

You can’t avoid the creation of duplicate code. But SonarQube will help you find code duplications in the same file, in the same project, or even across multiple projects, so you can clean up your duplications. There are four metrics related to code duplication.

What is SonarQube in Action Chapter 4?

Chapter 4. Working with duplicate code - SonarQube in Action Chapter 4. Working with duplicate code When you start a new project, you have a clean code base with no duplications, unless you copied another project to start with.

How does the issues workflow work in SonarQube?

SonarQube's issues workflow can help you manage your issues. There are seven different things you can do to an issue (other than fixing it in the code!): Comment, Assign, Confirm, Change Severity, Resolve, Won't Fix, and False Positive. These actions break out into three different categories.

What can I do with SonarQube?

Doing so allows you to remove noise, like the issues and duplications marked on generated code, or the issues from rules that aren't relevant for certain types of files. SonarQube gives you several options for configuring exactly what will be analyzed. You can


Video Answer


2 Answers

You can exclude this in Sonar by going to Administration > General Settings > Analysis Scope > Duplication Exclusions and excluding folders containing your entities - e.g. /entity/

like image 193
Franjo Markovic Avatar answered Oct 21 '22 09:10

Franjo Markovic


I'd say your choices are to extract a common ancestor class from Market and MarketDTO, or mark the duplicated blocks issues Won't Fix. (They're not really false positives, are they?)

like image 3
G. Ann - SonarSource Team Avatar answered Oct 21 '22 08:10

G. Ann - SonarSource Team