Hello SonarQube,
I think I have a false positive, and it is annoying us.
Language: Java
Rule: S2119, “Random” objects should be reused
I believe it’s a false-positive because there is only one Random
object, statically instantiated.
I’m using:
SonarQube server
Data Center Edition
v2026.1.2 (121356)
ACTIVE
Standard Experience
To reproduce the problem, submit this file to Sonar:
package com.example.mypackage;
import java.util.Random;
import java.util.stream.IntStream;
public final class SonarIssue {
public static final IntStream myInts = new Random().ints(0, 100);
private SonarIssue() {}
}
Sonar will report a Critical Bug:
Save and re-use this “Random”
What do you think? What should I do to not be annoyed by this
anymore? It is currently blocking in our Quality Gate and we have no way to disable the Gate.
Thanks a lot for your work!
Best regards
Fabrice