<qhelp>

<overview>

An integer multiplication that is assigned to a variable of type `long` or returned from a method with return type `long` may cause unexpected arithmetic overflow.

</overview> <recommendation>

Casting to type `long` before multiplying reduces the risk of arithmetic overflow.

</recommendation> <example>

In the following example, the multiplication expression assigned to `j` causes overflow and results in the value `-1651507200` instead of `4000000000000000000`.

In the following example, the assignment to `k` correctly avoids overflow by casting one of the operands to type `long`.

</example> <references>

- J. Bloch and N. Gafter, Java Puzzlers: Traps, Pitfalls, and Corner Cases, Puzzle 3. Addison-Wesley, 2005.
- The Java Language Specification: Multiplication Operator.
- The CERT Oracle Secure Coding Standard for Java: NUM00-J. Detect or prevent integer overflow.
</references> </qhelp>