diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java index 80c9d1c43a94b..8856654aed349 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java @@ -390,7 +390,7 @@ public static EnumSet asFlagSet(long flags) { public static final long SEALED = 1L<<62; // ClassSymbols /** - * Flag to indicate sealed class/interface declaration. + * Flag to indicate restricted method declaration. */ public static final long RESTRICTED = 1L<<62; // MethodSymbols @@ -400,7 +400,7 @@ public static EnumSet asFlagSet(long flags) { public static final long NON_SEALED = 1L<<63; // ClassSymbols /** - * Describe modifier flags as they migh appear in source code, i.e., + * Describe modifier flags as they might appear in source code, i.e., * separated by spaces and in the order suggested by JLS 8.1.1. */ public static String toSource(long flags) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index c390ad3d43124..fb0359e44641c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -289,7 +289,7 @@ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { */ public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) { if (lint.isEnabled(LintCategory.RESTRICTED)) - log.warning(LintCategory.RESTRICTED, pos, Warnings.RestrictedMethodCall(sym.enclClass(), sym)); + log.warning(LintCategory.RESTRICTED, pos, Warnings.RestrictedMethod(sym.enclClass(), sym)); } /** Warn about unchecked operation. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 1063372131492..1ff2f8d931423 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -1918,7 +1918,7 @@ compiler.warn.is.preview.reflective=\ {0} is a reflective preview API and may be removed in a future release. # 0: symbol, 1: symbol -compiler.warn.restricted.method.call=\ +compiler.warn.restricted.method=\ {0}.{1} is a restricted method.\n\ (Restricted methods are unsafe and, if used incorrectly, might crash the Java runtime or corrupt memory) diff --git a/test/langtools/tools/javac/RestrictedMethods.java b/test/langtools/tools/javac/RestrictedMethods.java index 94c3162ecd48a..4e3670f551c51 100644 --- a/test/langtools/tools/javac/RestrictedMethods.java +++ b/test/langtools/tools/javac/RestrictedMethods.java @@ -7,12 +7,18 @@ */ import java.lang.foreign.MemorySegment; +import java.util.function.Function; class RestrictedMethods { - MemorySegment warn = MemorySegment.NULL.reinterpret(10); + MemorySegment warn = MemorySegment.NULL.reinterpret(10); // warning here @SuppressWarnings("restricted") - MemorySegment suppressed = MemorySegment.NULL.reinterpret(10); + MemorySegment suppressed = MemorySegment.NULL.reinterpret(10); // no warning here + + Function warn_ref = MemorySegment.NULL::reinterpret; // warning here + + @SuppressWarnings("restricted") + Function suppressed_ref = MemorySegment.NULL::reinterpret; // no warning here void testWarn() { MemorySegment.NULL.reinterpret(10); // warning here @@ -23,12 +29,27 @@ void testSuppressed() { MemorySegment.NULL.reinterpret(10); // no warning here } + Function testWarnRef() { + return MemorySegment.NULL::reinterpret; // warning here + } + + @SuppressWarnings("restricted") + Function testSuppressedRef() { + return MemorySegment.NULL::reinterpret; // no warning here + } + @SuppressWarnings("restricted") static class Nested { - MemorySegment suppressedNested = MemorySegment.NULL.reinterpret(10); + MemorySegment suppressedNested = MemorySegment.NULL.reinterpret(10); // no warning here + + Function suppressedNested_ref = MemorySegment.NULL::reinterpret; // no warning here void testSuppressedNested() { MemorySegment.NULL.reinterpret(10); // no warning here } + + Function testSuppressedNestedRef() { + return MemorySegment.NULL::reinterpret; // no warning here + } } } diff --git a/test/langtools/tools/javac/RestrictedMethods.out b/test/langtools/tools/javac/RestrictedMethods.out index 097dc183ee030..abf4e1ee1fb4a 100644 --- a/test/langtools/tools/javac/RestrictedMethods.out +++ b/test/langtools/tools/javac/RestrictedMethods.out @@ -1,7 +1,9 @@ -RestrictedMethods.java:13:44: compiler.warn.restricted.method.call: java.lang.foreign.MemorySegment, reinterpret(long) -RestrictedMethods.java:18:27: compiler.warn.restricted.method.call: java.lang.foreign.MemorySegment, reinterpret(long) +RestrictedMethods.java:14:44: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long) +RestrictedMethods.java:18:49: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long) +RestrictedMethods.java:24:27: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long) +RestrictedMethods.java:33:16: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long) - compiler.err.warnings.and.werror - compiler.note.preview.filename: RestrictedMethods.java, DEFAULT - compiler.note.preview.recompile 1 error -2 warnings +4 warnings diff --git a/test/langtools/tools/javac/diags/examples.not-yet.txt b/test/langtools/tools/javac/diags/examples.not-yet.txt index 7251c56f74ab8..7245c10aa01a3 100644 --- a/test/langtools/tools/javac/diags/examples.not-yet.txt +++ b/test/langtools/tools/javac/diags/examples.not-yet.txt @@ -217,4 +217,4 @@ compiler.misc.illegal.signature # the compiler can compiler.err.annotation.unrecognized.attribute.name # this one is transitional (waiting for FFM API to exit preview) -compiler.warn.restricted.method.call +compiler.warn.restricted.method