-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8316971: Add Lint warning for restricted method calls
Reviewed-by: ihse, vromero
- Loading branch information
1 parent
d4c904d
commit 0d4de8a
Showing
15 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* @test /nodynamiccopyright/ | ||
* @bug 8316971 | ||
* @summary Smoke test for restricted method call warnings | ||
* @compile/fail/ref=RestrictedMethods.out -Xlint:restricted -Werror -XDrawDiagnostics --enable-preview --source ${jdk.version} RestrictedMethods.java | ||
* @compile -Werror --enable-preview --source ${jdk.version} RestrictedMethods.java | ||
*/ | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.util.function.Function; | ||
|
||
class RestrictedMethods { | ||
|
||
MemorySegment warn = MemorySegment.NULL.reinterpret(10); // warning here | ||
@SuppressWarnings("restricted") | ||
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 | ||
} | ||
|
||
@SuppressWarnings("restricted") | ||
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); // 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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 | ||
4 warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d4de8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues