Hi, I find that rule RSPEC-2119 cannot detect global variables. Please review the minimized sample below.
This is a false negative because rand is re-allocated by a new Random object at line 3. This violates the rule definition. Hence, I think we should restrict Random variable by final modifier, otherwise new Random object can lead to low performance and RNG prediction problem.
static Random rand = new Random(); // should report a warning here
public void foo() {
rand = new Random(); // Here, rand has been re-allocated
int rValue = rand.nextInt();
}
- Used versions
- sonarqube-9.2.2.50622
- sonar-scanner-cli-4.6.2.2472-linux