2
* @test /nodynamiccopyright/
4
* @summary Smoke test for restricted method call warnings
5
* @compile/fail/ref=RestrictedMethods.out -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
6
* @compile/fail/ref=RestrictedMethods.out --release ${jdk.version} -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
7
* @compile -Werror RestrictedMethods.java
10
import java.lang.foreign.MemorySegment;
11
import java.util.function.Function;
13
class RestrictedMethods {
15
MemorySegment warn = MemorySegment.NULL.reinterpret(10); // warning here
16
@SuppressWarnings("restricted")
17
MemorySegment suppressed = MemorySegment.NULL.reinterpret(10); // no warning here
19
Function<Integer, MemorySegment> warn_ref = MemorySegment.NULL::reinterpret; // warning here
21
@SuppressWarnings("restricted")
22
Function<Integer, MemorySegment> suppressed_ref = MemorySegment.NULL::reinterpret; // no warning here
25
MemorySegment.NULL.reinterpret(10); // warning here
28
@SuppressWarnings("restricted")
29
void testSuppressed() {
30
MemorySegment.NULL.reinterpret(10); // no warning here
33
Function<Integer, MemorySegment> testWarnRef() {
34
return MemorySegment.NULL::reinterpret; // warning here
37
@SuppressWarnings("restricted")
38
Function<Integer, MemorySegment> testSuppressedRef() {
39
return MemorySegment.NULL::reinterpret; // no warning here
42
@SuppressWarnings("restricted")
44
MemorySegment suppressedNested = MemorySegment.NULL.reinterpret(10); // no warning here
46
Function<Integer, MemorySegment> suppressedNested_ref = MemorySegment.NULL::reinterpret; // no warning here
48
void testSuppressedNested() {
49
MemorySegment.NULL.reinterpret(10); // no warning here
52
Function<Integer, MemorySegment> testSuppressedNestedRef() {
53
return MemorySegment.NULL::reinterpret; // no warning here