Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcimadamore committed Sep 29, 2023
1 parent 21b7d86 commit 1951b74
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static EnumSet<Flag> 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

Expand All @@ -400,7 +400,7 @@ public static EnumSet<Flag> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 24 additions & 3 deletions test/langtools/tools/javac/RestrictedMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, MemorySegment> warn_ref = MemorySegment.NULL::reinterpret; // warning here

@SuppressWarnings("restricted")
Function<Integer, MemorySegment> suppressed_ref = MemorySegment.NULL::reinterpret; // no warning here

void testWarn() {
MemorySegment.NULL.reinterpret(10); // warning here
Expand All @@ -23,12 +29,27 @@ void testSuppressed() {
MemorySegment.NULL.reinterpret(10); // no warning here
}

Function<Integer, MemorySegment> testWarnRef() {
return MemorySegment.NULL::reinterpret; // warning here
}

@SuppressWarnings("restricted")
Function<Integer, MemorySegment> 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<Integer, MemorySegment> suppressedNested_ref = MemorySegment.NULL::reinterpret; // no warning here

void testSuppressedNested() {
MemorySegment.NULL.reinterpret(10); // no warning here
}

Function<Integer, MemorySegment> testSuppressedNestedRef() {
return MemorySegment.NULL::reinterpret; // no warning here
}
}
}
8 changes: 5 additions & 3 deletions test/langtools/tools/javac/RestrictedMethods.out
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/diags/examples.not-yet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1951b74

Please sign in to comment.