...
A reviewer could now recognize that the operation should also be checked for overflow. This might not have been apparent in the original, noncompliant code example. See rule NUM00-J. Detect or prevent integer overflow for more information.
...
This noncompliant code example masks off the upper 24 bits of the promoted byte array element before performing the addition. The number of bits required to mask the sizes of byte
and int
are specified by the JLS The Java Language Specification. Although this code calculates the correct result, it violates this rule by combining bitwise and arithmetic operations on the same data.
...
INT14-C. Avoid performing bitwise and arithmetic operations on the same data | |
INT14-CPP. Avoid performing bitwise and arithmetic operations on the same data |
Bibliography
[FindBugs 2008] | |
[Seacord 2015] | NUM01-J. Do not perform bitwise and arithmetic operations on the same data LiveLesson |
...