Skip to content

False Negative : Overflowing int arithmetic assigned to long is missed #5672

@Carlson-JLQ

Description

@Carlson-JLQ

False Negative : Overflowing int arithmetic assigned to long is missed

Affects errorprone Version:

2.48.0

Checker:

IntLongMath

Description:

The official IntLongMath checker warns when an arithmetic expression is evaluated as int and only widened to long afterward, because overflow can already have happened in the intermediate computation. This sample is exactly that pattern.

Code Sample demonstrating the issue:

public class PosCase1 {
    public static void main(String[] args) {
        long result = 1000000 * 3000000;
        System.out.println(result);
    }
}

Both operands are int literals, so the multiplication is performed in int first. 1000000 * 3000000 exceeds Integer.MAX_VALUE, so the overflow happens before the value is assigned to long.

Expected outcome:

Error Prone should report IntLongMath here, but it doesn't. This is a false-negative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions