Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signedness Checker unable to know signedness of cast Object assigned to integral type #3668

Closed
DmitriyShepelev opened this issue Sep 17, 2020 · 0 comments · Fixed by #3688
Closed

Comments

@DmitriyShepelev
Copy link
Contributor

DmitriyShepelev commented Sep 17, 2020

The Signedness Checker is unable to know the signedness of a cast (without an explicit annotation) Object assigned to the integral types byte, short, int, and long:

import org.checkerframework.checker.signedness.qual.Signed;

public class ObjectCasts {
    void castObjectToBoxedVariants() {
        byte b1 = 1;
        short s1 = 1;
        int i1 = 1;
        long l1 = 1;
        Object[] obj = new Object[] {b1, s1, i1, l1};
        byteParameter((Byte) obj[0]);
        shortParameter((Short) obj[1]);
        integralParameter((Integer) obj[2]);
        longParameter((Long) obj[3]);
    }

    void byteParameter(byte b) {}

    void shortParameter(short s) {}

    void integralParameter(int i) {}

    void longParameter(long l) {}
}

Command: javacheck -version -verbose -AprintAllQualifiers -processor SignednessChecker ObjectCasts.java

Output:
ObjectCastsOutput.txt

javacheck alias:
alias javacheck='$CHECKERFRAMEWORK/checker/bin/javac'

What can be changed in the Signedness Checker to eliminate this type of error?

DmitriyShepelev added a commit to DmitriyShepelev/checker-framework that referenced this issue Sep 18, 2020
@mernst mernst linked a pull request Sep 23, 2020 that will close this issue
mernst added a commit to mernst/checker-framework that referenced this issue Sep 24, 2020
The main changes are to add a `@SignedPositiveFromUnsigned` annotation and to add logic related to the widening that Java automatically does at arithmetic operations.

Fixes typetools#3668; fixes typetools#3669
@DmitriyShepelev DmitriyShepelev changed the title Signedness Checker unable to know signedness of casted Object assigned to integral type Signedness Checker unable to know signedness of cast Object assigned to integral type Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant