File tree Expand file tree Collapse file tree 4 files changed +28
-9
lines changed
src/Likely Bugs/Arithmetic
test/query-tests/ConstantExpAppearsNonConstant Expand file tree Collapse file tree 4 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 1+ # Improvements to Java analysis
2+
3+ The following changes in version 1.24 affect Java analysis in all applications.
4+
5+ ## New queries
6+
7+ | ** Query** | ** Tags** | ** Purpose** |
8+ | -----------------------------| -----------| --------------------------------------------------------------------|
9+
10+ ## Changes to existing queries
11+
12+ | ** Query** | ** Expected impact** | ** Change** |
13+ | ------------------------------| ------------------------| -----------------------------------|
14+ | Expression always evaluates to the same value (` java/evaluation-to-constant ` ) | Fewer false positives | Expressions of the form ` 0 * x ` are usually intended and no longer reported. |
15+
16+ ## Changes to libraries
17+
Original file line number Diff line number Diff line change 7474 not child instanceof Annotation
7575 ) and
7676 not e instanceof CompileTimeConstantExpr and
77+ // Exclude explicit zero multiplication.
78+ not e .( MulExpr ) .getAnOperand ( ) .( IntegerLiteral ) .getIntValue ( ) = 0 and
7779 // Exclude expressions that appear to be disabled deliberately (e.g. `false && ...`).
7880 not e .( AndLogicalExpr ) .getAnOperand ( ) .( BooleanLiteral ) .getBooleanValue ( ) = false
7981select e , "Expression always evaluates to the same value."
Original file line number Diff line number Diff line change 1- | Test.java:18:33:18:49 | ... * ... | Expression always evaluates to the same value. |
2- | Test.java:19:34:19:50 | ... * ... | Expression always evaluates to the same value. |
3- | Test.java:20:29:20:48 | ... * ... | Expression always evaluates to the same value. |
4- | Test.java:21:32:21:50 | ... * ... | Expression always evaluates to the same value. |
1+ | Test.java:18:33:18:53 | ... * ... | Expression always evaluates to the same value. |
2+ | Test.java:19:34:19:54 | ... * ... | Expression always evaluates to the same value. |
3+ | Test.java:20:29:20:58 | ... * ... | Expression always evaluates to the same value. |
4+ | Test.java:21:32:21:69 | ... * ... | Expression always evaluates to the same value. |
55| Test.java:27:28:27:44 | ... % ... | Expression always evaluates to the same value. |
66| Test.java:29:29:29:48 | ... % ... | Expression always evaluates to the same value. |
77| Test.java:30:32:30:50 | ... % ... | Expression always evaluates to the same value. |
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ public void tester(){
1515 int mul_constant_left = 0 * 60 * 60 * 24 ; //OK
1616 int mul_constant_right = 60 * 60 * 24 * 0 ; //OK
1717 int mul_is_not_constant = rnd .nextInt () * 1 ; //OK
18- int mul_is_constant_int_left = 0 * rnd .nextInt (); //NOT OK
19- int mul_is_constant_int_right = rnd .nextInt () * 0 ; //NOT OK
20- long mul_is_constant_hex = rnd .nextLong () * 0x0 ; //NOT OK
21- long mul_is_constant_binary = rnd .nextLong () * 00 ; //NOT OK
22-
18+ int mul_is_constant_int_left = ( 0 + 0 ) * rnd .nextInt (); //NOT OK
19+ int mul_is_constant_int_right = rnd .nextInt () * ( 1 - 1 ) ; //NOT OK
20+ long mul_is_constant_hex = rnd .nextLong () * ( 0x0F & 0xF0 ) ; //NOT OK
21+ long mul_is_constant_binary = rnd .nextLong () * (0b010101 & 0b101010) ; //NOT OK
22+ int mul_explicit_zero = rnd . nextInt () * 0 ; //OK (deliberate zero multiplication)
2323 //Remainder by 1
2424 int rem_not_constant = 42 % 6 ; //OK
2525 int rem_constant = 60 % 1 ; //OK
You can’t perform that action at this time.
0 commit comments