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

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

Closed
violetagg opened this issue Mar 5, 2025 · 2 comments

Comments

@violetagg
Copy link

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

@msridhar
Copy link
Collaborator

msridhar commented Mar 5, 2025

Thanks for the report! This is #1075, and we should fix this particular case in #1131, which we're hoping to land soon! In the meantime, you can write AtomicReferenceFieldUpdater.<A, @Nullable Object>newUpdater(...) as a temporary workaround.

Will close as a duplicate for now

@msridhar msridhar closed this as completed Mar 5, 2025
@violetagg
Copy link
Author

Thanks

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