RFR: 8316971: Add Lint warning for restricted method calls [v3]

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Sep 29 08:30:07 UTC 2023

> This patch adds a new lint warning category, namely `-Xlint:restricted` to enable warnings on restricted method calls.
> The patch is relatively straightforward: javac marks methods that are marked with the `@Restricted` annotation with a corresponding internal flag. This is done both in `Annotate` when compiling JDK from source, and in `ClassReader` when JDK classfiles are read. When calls to methods marked with the special flag are found, a new warning is issued.
> While there are some similarities between this new warning and the preview API warnings, the compiler does *not* emit a mandatory note when a compilation unit is found to have one or more restricted method calls. In other words, this is just a plain lint warning.
> The output from javac looks as follows:
> Foo.java:6: warning: [restricted] MemorySegment.reinterpret(long) is a restricted method.
>       Arena.ofAuto().allocate(10).reinterpret(100);
>                                  ^
>   (Restricted methods are unsafe, and, if used incorrectly, they might crash the JVM or result in memory corruption)

Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:

  Address review comments


  - all: https://git.openjdk.org/jdk/pull/15964/files
  - new: https://git.openjdk.org/jdk/pull/15964/files/21b7d860..1951b742

 - full: https://webrevs.openjdk.org/?repo=jdk&pr=15964&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=15964&range=01-02

  Stats: 34 lines in 6 files changed: 23 ins; 0 del; 11 mod
  Patch: https://git.openjdk.org/jdk/pull/15964.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15964/head:pull/15964

PR: https://git.openjdk.org/jdk/pull/15964

More information about the compiler-dev mailing list