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

Array creation is intrinsically non-null #927

Open
wmdietl opened this issue Sep 27, 2024 · 2 comments · May be fixed by #928
Open

Array creation is intrinsically non-null #927

wmdietl opened this issue Sep 27, 2024 · 2 comments · May be fixed by #928
Assignees

Comments

@wmdietl
Copy link
Member

wmdietl commented Sep 27, 2024

I noticed when working on jspecify/jspecify#678 that the Nullness Checker currently accepts @Nullable on the created array:

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

public class ADemo {
  void foo() {
    int [] o = new int @Nullable [10];
    o.hashCode();
  }
}

An error is raised on the o.hashCode() even though that reference is intrinsically non-null.

Like for object creation, an array creation cannot be @Nullable. (Check other possible qualifiers, also initialization).

@thisisalexandercook
Copy link
Collaborator

@wmdietl I'm unable to reproduce the error raised on o.hashCode but will work on updating checker to not accept qualifier on array creation.

@wmdietl
Copy link
Member Author

wmdietl commented Sep 28, 2024

Ah, I had used a 2 year old CF version... that produced:

> ./checker/bin/javac -processor nullness ADemo.java
ADemo.java:6: error: [dereference.of.nullable] dereference of possibly-null reference o
    o.hashCode();
    ^
1 error

It doesn't really make sense, because the logic that makes array creations non-null has been there for a long while.

Let's just produce a warning that the @Nullable in the example is ignored.

@thisisalexandercook thisisalexandercook linked a pull request Sep 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants