Hi Team,
Both code snippets below violate RSPEC-2116. One code snippet is a variant of the first one, meaning the bug violation should be detected in both code snippets; however, scanning shows that the bug is found in “Code snippet 1” but not the variant labelled “Code snippet 2”. Violation of this bug rule is not consistently flagged.
Code snippet 1:
import java.util.*;
class BuggyArray {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
System.out.println("Hash code: " + numbers.hashCode());
System.out.println("ToString: " + numbers.toString());
}
}
Code snippet 2:
import java.util.*;
class BuggyArray
{
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
int deadStore = 1; // Dead Store Mutant
System.out.println("Hash code: " + numbers.hashCode());
System.out.println("ToString: " + numbers.toString());
}
}
screenshot from sonarqube window for code snippet 1 showing the bug being correctly flagged:
screenshot fron sonarqube window for code snippet 2:
Scanning information:
Sonarqube version: 10.7.0.96327
SonarScanner version: 5.0.1.3006
SonarQube Community Edition
Related language: Java
Thanks for your time and consideration.