diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReference.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReference.java index e512c91f2df..1d7268609d7 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReference.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReference.java @@ -279,6 +279,7 @@ public class AtomicReference implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final V getPlain() { return (V)VALUE.get(this); } @@ -302,6 +303,7 @@ public class AtomicReference implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final V getOpaque() { return (V)VALUE.getOpaque(this); } @@ -324,6 +326,7 @@ public class AtomicReference implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final V getAcquire() { return (V)VALUE.getAcquire(this); } @@ -351,6 +354,7 @@ public class AtomicReference implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final V compareAndExchange(V expectedValue, V newValue) { return (V)VALUE.compareAndExchange(this, expectedValue, newValue); } @@ -367,6 +371,7 @@ public class AtomicReference implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final V compareAndExchangeAcquire(V expectedValue, V newValue) { return (V)VALUE.compareAndExchangeAcquire(this, expectedValue, newValue); } @@ -383,6 +388,7 @@ public class AtomicReference implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final V compareAndExchangeRelease(V expectedValue, V newValue) { return (V)VALUE.compareAndExchangeRelease(this, expectedValue, newValue); } diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java index e8238320e21..ec00f40a568 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java @@ -358,6 +358,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final E getPlain(int i) { return (E)AA.get(array, i); } @@ -383,6 +384,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final E getOpaque(int i) { return (E)AA.getOpaque(array, i); } @@ -407,6 +409,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * @return the value * @since 9 */ + @SuppressWarnings("unchecked") public final E getAcquire(int i) { return (E)AA.getAcquire(array, i); } @@ -437,6 +440,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final E compareAndExchange(int i, E expectedValue, E newValue) { return (E)AA.compareAndExchange(array, i, expectedValue, newValue); } @@ -455,6 +459,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final E compareAndExchangeAcquire(int i, E expectedValue, E newValue) { return (E)AA.compareAndExchangeAcquire(array, i, expectedValue, newValue); } @@ -473,6 +478,7 @@ public class AtomicReferenceArray implements java.io.Serializable { * expected value if successful * @since 9 */ + @SuppressWarnings("unchecked") public final E compareAndExchangeRelease(int i, E expectedValue, E newValue) { return (E)AA.compareAndExchangeRelease(array, i, expectedValue, newValue); } diff --git a/src/java.base/share/classes/java/util/stream/ForEachOps.java b/src/java.base/share/classes/java/util/stream/ForEachOps.java index 1ba59709152..6163ed4061e 100644 --- a/src/java.base/share/classes/java/util/stream/ForEachOps.java +++ b/src/java.base/share/classes/java/util/stream/ForEachOps.java @@ -505,6 +505,7 @@ final class ForEachOps { // "happens-before" completion of the associated left-most leaf task // of right subtree (if any, which can be this task's right sibling) // + @SuppressWarnings("unchecked") var leftDescendant = (ForEachOrderedTask)NEXT.getAndSet(this, null); if (leftDescendant != null) leftDescendant.tryComplete(); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java index 0c589c54edd..4a226e4de3b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java @@ -263,6 +263,7 @@ public enum Source { FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL), MODULE_IMPORTS(JDK23, Fragments.FeatureModuleImports, DiagKind.PLURAL), PRIVATE_MEMBERS_IN_PERMITS_CLAUSE(JDK19), + ERASE_POLY_SIG_RETURN_TYPE(JDK24), ; enum DiagKind { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java index 81e07277bfb..d590c62f27f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java @@ -100,6 +100,8 @@ public class Infer { private final boolean dumpStacktraceOnError; + private final boolean erasePolySigReturnType; + public static Infer instance(Context context) { Infer instance = context.get(inferKey); if (instance == null) @@ -123,6 +125,8 @@ public class Infer { emptyContext = new InferenceContext(this, List.nil()); dumpStacktraceOnError = options.isSet("dev") || options.isSet(DOE); + Source source = Source.instance(context); + erasePolySigReturnType = Source.Feature.ERASE_POLY_SIG_RETURN_TYPE.allowedInSource(source); } /** A value for prototypes that admit any type, including polymorphic ones. */ @@ -544,8 +548,8 @@ public class Infer { case TYPECAST: JCTypeCast castTree = (JCTypeCast)env.next.tree; restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? - castTree.clazz.type : - spType; + (erasePolySigReturnType ? types.erasure(castTree.clazz.type) : castTree.clazz.type) : + spType; break; case EXEC: JCTree.JCExpressionStatement execTree = diff --git a/src/jdk.dynalink/share/classes/jdk/dynalink/BiClassValue.java b/src/jdk.dynalink/share/classes/jdk/dynalink/BiClassValue.java index a1faf464ea6..4a540be5377 100644 --- a/src/jdk.dynalink/share/classes/jdk/dynalink/BiClassValue.java +++ b/src/jdk.dynalink/share/classes/jdk/dynalink/BiClassValue.java @@ -113,6 +113,7 @@ final class BiClassValue { } private T compute(final VarHandle mapHandle, final Class c, final Function, T> compute) { + @SuppressWarnings("unchecked") Map, T> map = (Map, T>) mapHandle.getVolatile(this); T value; T newValue = null; @@ -127,6 +128,7 @@ final class BiClassValue { final Map.Entry, T>[] entries = map.entrySet().toArray(new Map.Entry[map.size() + 1]); entries[map.size()] = Map.entry(c, newValue); final var newMap = Map.ofEntries(entries); + @SuppressWarnings("unchecked") final var witness = (Map, T>) mapHandle.compareAndExchange(this, map, newMap); if (witness == map) { value = newValue; diff --git a/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.java b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.java new file mode 100644 index 00000000000..f0754c3cf73 --- /dev/null +++ b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.java @@ -0,0 +1,12 @@ +/* + * /nodynamiccopyright/ + */ + +import java.lang.invoke.VarHandle; + +class PolymorphicMethodTest { + VarHandle vh; + V method(Object obj) { + return (V)vh.getAndSet(this, obj); + } +} diff --git a/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.out b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.out new file mode 100644 index 00000000000..71abb004318 --- /dev/null +++ b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest.out @@ -0,0 +1,2 @@ +PolymorphicMethodTest.java:10:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Object, V +1 warning diff --git a/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest_Source23.out b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest_Source23.out new file mode 100644 index 00000000000..5694d9ea4f6 --- /dev/null +++ b/test/langtools/tools/javac/mandatoryWarnings/unchecked/PolymorphicMethodTest_Source23.out @@ -0,0 +1,2 @@ +- compiler.warn.source.no.system.modules.path: 23, (compiler.misc.source.no.system.modules.path: 23) +1 warning diff --git a/test/langtools/tools/javac/mandatoryWarnings/unchecked/Test.java b/test/langtools/tools/javac/mandatoryWarnings/unchecked/Test.java index 434889cb8ec..759c4090e1c 100644 --- a/test/langtools/tools/javac/mandatoryWarnings/unchecked/Test.java +++ b/test/langtools/tools/javac/mandatoryWarnings/unchecked/Test.java @@ -42,4 +42,6 @@ * @compile/ref=Test4b.out -XDrawDiagnostics -nowarn -Xlint:unchecked -Xmaxwarns 1 A.java B.java * @compile/ref=Test4c.out -XDrawDiagnostics -nowarn -Xlint:unchecked -Xmaxwarns 2 A.java B.java * @compile/ref=Test4d.out -XDrawDiagnostics -nowarn -Xlint:unchecked -Xmaxwarns 3 A.java B.java + * @compile/ref=PolymorphicMethodTest.out -XDrawDiagnostics -Xlint:unchecked PolymorphicMethodTest.java + * @compile/ref=PolymorphicMethodTest_Source23.out -XDrawDiagnostics -Xlint:unchecked -source 23 PolymorphicMethodTest.java */