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

PolyNull Object as receiver error #532

Closed
Ao-senXiong opened this issue Jun 29, 2023 · 4 comments · Fixed by #540
Closed

PolyNull Object as receiver error #532

Ao-senXiong opened this issue Jun 29, 2023 · 4 comments · Fixed by #540

Comments

@Ao-senXiong
Copy link
Member

Ao-senXiong commented Jun 29, 2023

In this code snippet, the expected error is dereferenc of possibly-null reference nbl. However, a method invocation invalid error is also raised.

import org.checkerframework.checker.nullness.qual.PolyNull;

class Demo {
    void foo(@PolyNull Object nbl) {
        if (nbl == null) {
            nbl.toString();
        }
    }
}

Error message is listing for reference:

Demo.java:6: error: [dereference.of.nullable] dereference of possibly-null reference nbl
            nbl.toString();
            ^
Demo.java:6: error: [method.invocation.invalid] call to toString() not allowed on the given receiver.
            nbl.toString();
                        ^
  found   : @FBCBottom @PolyNull Object
  required: @Initialized @NonNull Object

Another code snippet with @Nullable annotation is

import org.checkerframework.checker.nullness.qual.Nullable;

class Demo {
    void foo(@Nullable Object nbl) {
        if (nbl == null) {
            nbl.toString();
        }
    }
}

And the corresponding error message are listing below

Demo.java:6: error: [dereference.of.nullable] dereference of possibly-null reference nbl
            nbl.toString();
            ^
1 error

@wmdietl
Copy link
Member

wmdietl commented Jun 29, 2023

This came up here: #525 (comment) . Try to keep references between different issues and PRs, to make the history easier to follow.

It's noteworthy here that a different error is issued for @Nullable instead of @PolyNull in this test case.

@Ao-senXiong
Copy link
Member Author

This came up here: #525 (comment) . Try to keep references between different issues and PRs, to make the history easier to follow.

It's noteworthy here that a different error is issued for @Nullable instead of @PolyNull in this test case.

Thanks, already added.

@Ao-senXiong
Copy link
Member Author

For a simpler case without dataflow refinement, I think we are still expecting to dereference possible-null reference errors because of soundness.

import org.checkerframework.checker.nullness.qual.PolyNull;

class Demo {
    void foo(@PolyNull Object nbl) {
            nbl.toString();
    }
}

@wmdietl
Copy link
Member

wmdietl commented Jul 3, 2023

Yes, directly dereferencing a PolyNull reference should give you an error, like for a Nullable reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants