...
The intent of the expression in this noncompliant code example is to add the variable OFFSET with the result of the bitwise and between x and MASK.
Code Block | ||
---|---|---|
| ||
public static final int MASK = 1337; public static final int OFFSET = -1337; public static int computeCode(int x) { return x & MASK + OFFSET; } |
Because of operator precedence rules, the expression is parsed as
Code Block | ||
---|---|---|
| ||
x & (MASK + OFFSET) |
Which gets evaluated as
Code Block | ||
---|---|---|
| ||
x & (1337 - 1337)
|
Resulting in 0.
Compliant Solution
In this compliant solution, parentheses are used to ensure the expression evaluates as expected.
...