Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reverted from v. 36

...

If an integer operator other than a shift operator has at least one operand of type long, then the operation is carried out using 64-bit precision, and the result of the numerical operator is of type long. If the other operand is not long, it is first widened (§5§5.1.5) to type long by numeric promotion (§5§5.6). Otherwise, the operation is carried out using 32-bit precision, and the result of the numerical operator is of type int. If either operand is not an int, it is first widened to type int by numeric promotion.

...

Code Block
bgColor#ccccff
int result = 0;
for(int i = 0; i < 4; i++) 
  result = ((result << 8) | (b[i] &amp; 0xff));

Risk Assessment

Failing to consider integer promotions when dealing with floating point and integer operands can result in loss of precision.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[JLS 05|AA. Java References#JLS 05]\] 4.2.2 "Integer Operations" and 5.6 "Numeric Promotions" 
\[[Findbugs 08|AA. Java References#Findbugs 08]\] "BIT: Bitwise OR of signed byte value"

...