Sonar CPD Detects Duplication Blocks
I did so much analysis on how cpd sonar detects duplicate blocks. But I can't figure out exactly what process is required to detect blocks or lines of code. They have a minimum number of lines.
For example, if I write like below, it doesn't detect any duplicate code, even repeating over 20 times.
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
Later I tried to do duplicate blocks
try
{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try
{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
It is seen here as two blocks, although it has many blocks.
Please let me know the exact process that follows in this sonar overlap detection 3.4.1
In this http://docs.sonarsource.org/3.1/apidocs/src-html/org/sonar/plugins/cpd/SonarEngine.html
I found the constant block size to be 10. But I can relate this in my observation.
+3
source to share