diff --git a/src/java.base/share/classes/java/lang/ScopedValue.java b/src/java.base/share/classes/java/lang/ScopedValue.java index 866e575390abe..206c81d5238ec 100644 --- a/src/java.base/share/classes/java/lang/ScopedValue.java +++ b/src/java.base/share/classes/java/lang/ScopedValue.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2020, 2022, Red Hat Inc. + * Copyright (c) 2020, 2025, Red Hat Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,7 +34,6 @@ import java.util.function.Supplier; import jdk.internal.access.JavaUtilConcurrentTLRAccess; import jdk.internal.access.SharedSecrets; -import jdk.internal.javac.PreviewFeature; import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.Hidden; import jdk.internal.vm.ScopedValueContainer; @@ -237,9 +236,8 @@ * have to be regenerated after a blocking operation. * * @param the type of the value - * @since 21 + * @since 25 */ -@PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) public final class ScopedValue { private final int hash; @@ -310,9 +308,8 @@ Object find(ScopedValue key) { *

Unless otherwise specified, passing a {@code null} argument to a method in * this class will cause a {@link NullPointerException} to be thrown. * - * @since 21 + * @since 25 */ - @PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) public static final class Carrier { // Bit masks: a 1 in position n indicates that this set of bound values // hits that slot in the cache. @@ -413,7 +410,6 @@ public T get(ScopedValue key) { * @return the result * @throws StructureViolationException if a structure violation is detected * @throws X if {@code op} completes with an exception - * @since 23 */ public R call(CallableOp op) throws X { Objects.requireNonNull(op); @@ -497,9 +493,8 @@ private void runWith(Snapshot newSnapshot, Runnable op) { * * @param result type of the operation * @param type of the exception thrown by the operation - * @since 23 + * @since 25 */ - @PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) @FunctionalInterface public interface CallableOp { /** @@ -612,10 +607,11 @@ private Object findBinding() { * Returns the value of this scoped value if bound in the current thread, otherwise * returns {@code other}. * - * @param other the value to return if not bound, can be {@code null} + * @param other the value to return if not bound * @return the value of the scoped value if bound, otherwise {@code other} */ public T orElse(T other) { + Objects.requireNonNull(other); Object obj = findBinding(); if (obj != Snapshot.NIL) { @SuppressWarnings("unchecked") diff --git a/src/java.base/share/classes/javax/security/auth/Subject.java b/src/java.base/share/classes/javax/security/auth/Subject.java index ceb860e653a53..dd1e2333005a9 100644 --- a/src/java.base/share/classes/javax/security/auth/Subject.java +++ b/src/java.base/share/classes/javax/security/auth/Subject.java @@ -300,7 +300,7 @@ public static Subject getSubject(final AccessControlContext acc) { * @since 18 */ public static Subject current() { - return SCOPED_SUBJECT.orElse(null); + return SCOPED_SUBJECT.isBound() ? SCOPED_SUBJECT.get() : null; } /** diff --git a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java index 80593c5453a2a..1f28864b4db30 100644 --- a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java +++ b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java @@ -69,7 +69,6 @@ public enum Feature { //--- IMPLICIT_CLASSES, //to be removed when boot JDK is 25 - @JEP(number=487, title="Scoped Values", status="Fourth Preview") SCOPED_VALUES, @JEP(number=505, title="Structured Concurrency", status="Fifth Preview") STRUCTURED_CONCURRENCY, diff --git a/test/jdk/java/lang/ScopedValue/ManyBindings.java b/test/jdk/java/lang/ScopedValue/ManyBindings.java index 48751ae039f62..5f9b5e6e17679 100644 --- a/test/jdk/java/lang/ScopedValue/ManyBindings.java +++ b/test/jdk/java/lang/ScopedValue/ManyBindings.java @@ -24,7 +24,6 @@ /* * @test * @summary Stress test ScopedValue with many bindings and rebindings - * @enablePreview * @library /test/lib * @key randomness * @run junit ManyBindings diff --git a/test/jdk/java/lang/ScopedValue/ScopedValueAPI.java b/test/jdk/java/lang/ScopedValue/ScopedValueAPI.java index 3cb96533cc424..5652de7e10ebf 100644 --- a/test/jdk/java/lang/ScopedValue/ScopedValueAPI.java +++ b/test/jdk/java/lang/ScopedValue/ScopedValueAPI.java @@ -24,7 +24,6 @@ /* * @test * @summary Test ScopedValue API - * @enablePreview * @run junit ScopedValueAPI */ @@ -175,18 +174,15 @@ void testIsBound(ThreadFactory factory) throws Exception { void testOrElse(ThreadFactory factory) throws Exception { test(factory, () -> { ScopedValue name = ScopedValue.newInstance(); - assertNull(name.orElse(null)); assertEquals("default", name.orElse("default")); // where ScopedValue.where(name, "duke").run(() -> { - assertEquals("duke", name.orElse(null)); assertEquals("duke", name.orElse("default")); }); // callWhere ScopedValue.where(name, "duke").call(() -> { - assertEquals("duke", name.orElse(null)); assertEquals("duke", name.orElse("default")); return null; }); @@ -416,6 +412,7 @@ void testNullPointerException() { assertThrows(NullPointerException.class, () -> ScopedValue.where(null, "duke").call(() -> "")); assertThrows(NullPointerException.class, () -> ScopedValue.where(name, "duke").call(null)); + assertThrows(NullPointerException.class, () -> name.orElse(null)); assertThrows(NullPointerException.class, () -> name.orElseThrow(null)); var carrier = ScopedValue.where(name, "duke"); @@ -423,6 +420,7 @@ void testNullPointerException() { assertThrows(NullPointerException.class, () -> carrier.get((ScopedValue)null)); assertThrows(NullPointerException.class, () -> carrier.run(null)); assertThrows(NullPointerException.class, () -> carrier.call(null)); + assertThrows(NullPointerException.class, () -> carrier.run(() -> name.orElse(null))); } @FunctionalInterface diff --git a/test/jdk/java/lang/ScopedValue/UnboundValueAfterOOME.java b/test/jdk/java/lang/ScopedValue/UnboundValueAfterOOME.java index 87183775266c0..78fef93161723 100644 --- a/test/jdk/java/lang/ScopedValue/UnboundValueAfterOOME.java +++ b/test/jdk/java/lang/ScopedValue/UnboundValueAfterOOME.java @@ -26,7 +26,6 @@ /* * @test * @bug 8319120 - * @enablePreview * @run main/othervm -Xmx10m UnboundValueAfterOOME */ public class UnboundValueAfterOOME {