mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
Add support for Commons-Lang's RandomUtils
This is realised by somewhat generalising our interfaces for modelling RNGs. We also add tests for randomness-related queries that didn't have any, and addtest cases checking the Apache random-number generators are interchangeable with the stdlib ones.
This commit is contained in:
20
java/ql/test/query-tests/BadAbsOfRandom/Test.java
Normal file
20
java/ql/test/query-tests/BadAbsOfRandom/Test.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.util.Random;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void test() {
|
||||
|
||||
Random r = new Random();
|
||||
Math.abs(r.nextInt());
|
||||
Math.abs(r.nextLong());
|
||||
Math.abs(r.nextInt(100)); // GOOD: random value already has a restricted range
|
||||
|
||||
Math.abs(RandomUtils.nextInt());
|
||||
Math.abs(RandomUtils.nextLong());
|
||||
Math.abs(RandomUtils.nextInt(1, 10)); // GOOD: random value already has a restricted range
|
||||
Math.abs(RandomUtils.nextLong(1, 10)); // GOOD: random value already has a restricted range
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user