Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.12
-
Fix Version/s: 2.11
-
Component/s: Duplications
-
Labels:None
-
Environment:Sonar runs on Red Hat Linux, connects to Oracle database, fetches code from CVS repository in a GForge installation.
-
Number of attachments :
Description
We set up the "Settings -> CPD Plugin -> Ignore Literals" to be "true".
Sonar correctly detected this code to be copy/paste (code paraphrased):
List peopleList = new ArrayList();
peopleList.add("a name");
peopleList.add("some name");
peopleList.add("another name");
peopleList.add("some other name");
was a copy of
List houseList = new ArrayList();
houseList.add("a house");
houseList.add("some house");
houseList.add("another house");
houseList.add("some other house");
For reasons beyond the scope of this bug, we need the strings to be in the code. So we changed the code into:
String [] people = new String[]
;
and
String [] houses = new String[]
;
The string arrays are also detected as duplicates. Although I technically understand why this is happening, I think this prevents developers from creating multiple large arrays with strings in any part of the code.
Is this the desired effect and if so, how do the people who wrote the CPD plugin suggest this is solved, given that the strings can not be externalized (the need to be part of the code, per requirement of the customer).
Issue Links
- relates to
-
SONAR-1091
Copy Paste Code checking over all Projects
-
You're right Rolf.
When the "Ignore Literals" is set to false, the statement "peopleList.add("a name").add("another name")" is tokenized to get the following tokens : 'people', 'add', 'a name', 'add', 'another name'.
When the "Ignore Literals" is set to true, with the same statement, we get the following list of tokens : 'people', 'add', 'literal', 'add', 'literal'.
In fact 'literal' token should not be included in the token list and we should get 'people', 'add', 'add'.
if you agree, I'm going to change the type of this ticket from Bug to Improvement.