Hi Team,
The code snippet 1 correctly flagged the violation of this rule, RSPEC-1217, while code snippet 2, a variant of the previous Java class, didn’t flag the violation of that rule. So this bug rule is not consistenly being flagged.
Code snippet 1:
class ThreadBug {
public static void main(String[] args) {
Thread t = new Thread();
t.run();
}
public static void showBug() {
Thread t = new Thread(new Runnable() {
public void run() {
System.out.println("This is a bug");
}
});
t.run();
}
}
Code snippet 2:
class ThreadBug
{
public static void main(String[] args) {
Thread t = new Thread();
t.run();
int value = 0;
switch (value) {
case 1:
System.out.println("This code is unreachable");
break;
default:
System.out.println("This code is also unreachable");
break;
}
}
public static void showBug() {
Thread t = new Thread(new Runnable() {
public void run() {
System.out.println("This is a bug");
}
});
t.run();
}
}
Scanning information:
Sonarqube version: 10.7.0.96327
SonarScanner version: 5.0.1.3006
SonarQube Community Edition
Related language: Java
Note: To recreate the issues, sonar-scanner can be used to scan both code snippets in seperate .java files.
screenshot from the scanning window for code snippet 1:
screenshot from the scanning window for code snippet 2: