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 return value is broken when returning null #6676

Closed
alexvas opened this issue Jun 24, 2024 · 2 comments
Closed

Array return value is broken when returning null #6676

alexvas opened this issue Jun 24, 2024 · 2 comments

Comments

@alexvas
Copy link

alexvas commented Jun 24, 2024

Commands

java -version -Aversion -AprintGitProperties -verbose -AprintVerboseGenerics
java -jar "$CHECKER_FRAMEWORK/checker/dist/checker.jar" -processor nullness Foo.java

Inputs

A single input named Foo.java:

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

interface Foo {
}

interface Bar {

	default @Nullable Foo[] bazz() {
		return null;
	}
}

Outputs

openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 17.0.11+9-Ubuntu-122.04.1, mixed mode, sharing)
Foo.java:9: error: [return] incompatible types in return.
                return null;
                       ^
  type of expression: null (NullType)
  method return type: @Initialized @Nullable Foo @Initialized @NonNull []
1 error

Expectation

The case is valid. No error should be issued.

@msridhar
Copy link
Contributor

msridhar commented Jun 24, 2024

I think you need to write Foo @Nullable [] since it's a type use annotation. @Nullable Foo [] means the pointers inside the array to the Foo objects may be null.

@alexvas
Copy link
Author

alexvas commented Jun 24, 2024

@msridhar, Thank you. My bad.

@alexvas alexvas closed this as completed Jun 24, 2024
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

No branches or pull requests

2 participants