typetools / typetools/checker-framework

Can't define Nullness for generic class argument

Open
#2,448 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

False Positive (false warning or imprecision)
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

I'm trying to use xnio Option with @Nullable annotation but cann't provide Class<@Nullable String> object as function argument:

M.java:

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

class M {
	static class Option<T> {}
	
	static <T> Option<T> get(Class<T> klass) {
		throw new UnsupportedOperationException();
	}
	
	static final Option<@Nullable String> V = get(String.class);
}

Command to run:

"C:\Program Files\Java\jdk1.8.0_202\bin\javac.exe" -version -verbose -AprintAllQualifiers -processor org.checkerframework.checker.nullness.NullnessChecker -cp C:\Users\oleg_schelicalnov\.gradle\caches\modules-2\files-2.1\org.checkerframework\checker\2.5.7\4f6651c1f11f89565c6515eca445073265ce0464\checker-2.5.7.jar;C:\Users\oleg_schelicalnov\.gradle\caches\modules-2\files-2.1\org.checkerframework\checker-qual\2.5.72bd4f1921c78c2adffbe2eb01117c7936d0a0789\checker-qual-2.5.7.jar -Xbootclasspath/p:C:\Users\oleg_schelicalnov\.gradle\caches\modules-2\files-2.1\org.checkerframework\jdk8\2.5.7\61e56156f39f68d66ca6dcbe6931c3d9c73d7a0\jdk8-2.5.7.jar M.java

Error:

M.java:10: error: [assignment.type.incompatible] incompatible types in assignment.

	static final Option<@Nullable String> V = get(String.class);
	                                             ^
  found   : @Initialized @NonNull Option<@Initialized @NonNull String>

  required: @Initialized @NonNull Option<@Initialized @Nullable String>
[total 1587ms]
1 error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the M.java reproducer and run the supplied javac command using NullnessChecker. Trace how the checker handles get(String.class) when assigning to Option<@Nullable String>; done means the reported incompatible-assignment error is resolved for this example without weakening the intended nullness checking.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.