From 3e9473d1400a3af791d94d0b01f9b3bc7f936578 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Mon, 7 Oct 2024 10:48:41 -0400 Subject: [PATCH] Annotate `ScopedValue.orElse`. (#93) I'm doing this entirely in response to an observation that this is a new API that would benefit from `@PolyNull`: https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2147#issuecomment-1997570950 I haven't tried to annotate the rest of the class. --- src/java.base/share/classes/java/lang/ScopedValue.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/lang/ScopedValue.java b/src/java.base/share/classes/java/lang/ScopedValue.java index 635fadfa8c8..8f6291b0431 100644 --- a/src/java.base/share/classes/java/lang/ScopedValue.java +++ b/src/java.base/share/classes/java/lang/ScopedValue.java @@ -26,6 +26,8 @@ package java.lang; +import org.jspecify.annotations.Nullable; + import java.util.NoSuchElementException; import java.util.Objects; import java.lang.ref.Reference; @@ -684,7 +686,7 @@ private Object findBinding() { * @param other the value to return if not bound, can be {@code null} * @return the value of the scoped value if bound, otherwise {@code other} */ - public T orElse(T other) { + public @Nullable T orElse(@Nullable T other) { Object obj = findBinding(); if (obj != Snapshot.NIL) { @SuppressWarnings("unchecked")