Skip to content

Mismatched nullability of type parameters when using Nullable with AtomicReferenceFieldUpdater #1157

@violetagg

Description

@violetagg

I have a problem when I try to use @Nullable and AtomicReferenceFieldUpdater , this snippet:

class A {
	static final AtomicReferenceFieldUpdater<A, @Nullable Object> RESULT_UPDATER =
			AtomicReferenceFieldUpdater.newUpdater(A.class, Object.class, "result");
	volatile @Nullable Object result;

	A() {
		System.out.println("Set operation result " + RESULT_UPDATER.compareAndSet(this, null, new Object()));
	}
}

Gives the following error:

/nullaway-mismatched-nullability/src/main/java/org/example/A.java:8: error: [NullAway] Cannot assign from type AtomicReferenceFieldUpdater<A, Object> to type AtomicReferenceFieldUpdater<A, @Nullable Object> due to mismatched nullability of type parameters
	static final AtomicReferenceFieldUpdater<A, @Nullable Object> RESULT_UPDATER =
	                                                              ^

The repository with the reproducible example can be found here
https://github.com/violetagg/nullaway-mismatched-nullability

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions