Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333560

-Xlint:restricted does not work with --release

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 22
    • tools
    • None
    • b26

      $ cat Main.java

      package main;

      import java.lang.foreign.*;

      public class Main {
          public static void main(String[] args) {
              MemorySegment.ofAddress(1234).reinterpret(10);
          }
      }

      $ javac -d classes '-Xlint:restricted' Main.java
      Main.java:7: warning: [restricted] MemorySegment.reinterpret(long) is a restricted method.
              MemorySegment.ofAddress(1234).reinterpret(10);
                                           ^
        (Restricted methods are unsafe and, if used incorrectly, might crash the Java runtime or corrupt memory)
      1 warning

      $ javac -d classes --release 22 '-Xlint:restricted' Main.java
      <no output>

      The jdk.internal.javac.Restricted is not preserved when creating the symbol files in ./make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java

      However, javac needs this annotation to be present in order to detect restricted methods.

      A simple fix is to add this annotation to the list of hard-coded annotation that gets preserved (along with e.g. jdk.internal.javac.PreviewFeature)

            jvernee Jorn Vernee
            jvernee Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: