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

'internal proprietary API' warnings make javac warnings unusable

XMLWordPrintable

    • b10

        Using this small reproducer:
        ```java
        import sun.misc.Signal;
        import sun.misc.Unsafe;

        import java.lang.reflect.Field;

        public class MyLibrary {

            @SuppressWarnings("removal")
            public static void main(String[] args) throws InterruptedException {
                System.out.println("pageSize = " + UNSAFE.pageSize());

                long pointer = UNSAFE.allocateMemory(8);
                System.out.println("pointer = " + pointer);
                // Imagine some more useful logic with the pointer, just keeping the example short here

                Signal.handle((Signal) new Signal("INT"), signal -> {
                    // Imagine some more useful signal handler, just keeping the example short here
                    System.out.println("Bye");
                    System.exit(0);
                });

                System.out.println("Sleeping");
                Thread.sleep(30 * 1000);
            }

            private static final Unsafe UNSAFE = getUnsafe();

            @SuppressWarnings("restriction")
            private static Unsafe getUnsafe() {
                try {
                    Field field = Unsafe.class.getDeclaredField("theUnsafe");
                    field.setAccessible(true);
                    return (Unsafe) field.get(null);
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    throw new Error(e);
                }
            }

        }
        ```

        On JDK 24+22 or before, everything is fine:
        ```
        $ javac -Xlint:all -XDignore.symbol.file MyLibrary.java
        MyLibrary.java:15: warning: [cast] redundant cast to Signal
                Signal.handle((Signal) new Signal("INT"), signal -> {
                              ^
        Note: MyLibrary.java uses or overrides a deprecated API that is marked for removal.
        Note: Recompile with -Xlint:removal for details.
        1 warning
        # Fixing the warning
        $ javac -Werror -Xlint:all -XDignore.symbol.file MyLibrary.java
        Note: MyLibrary.java uses or overrides a deprecated API that is marked for removal.
        Note: Recompile with -Xlint:removal for details.
        [exit code success]
        ```

        Compiling it with javac on JDK 24+23 or more recent gives:
        ```
        $ javac -Xlint:all -XDignore.symbol.file MyLibrary.java
        MyLibrary.java:1: warning: Signal is internal proprietary API and may be removed in a future release
        import sun.misc.Signal;
                       ^
        MyLibrary.java:2: warning: Unsafe is internal proprietary API and may be removed in a future release
        import sun.misc.Unsafe;
                       ^
        MyLibrary.java:15: warning: Signal is internal proprietary API and may be removed in a future release
                Signal.handle((Signal) new Signal("INT"), signal -> {
                               ^
        MyLibrary.java:15: warning: Signal is internal proprietary API and may be removed in a future release
                Signal.handle((Signal) new Signal("INT"), signal -> {
                                           ^
        MyLibrary.java:15: warning: [cast] redundant cast to Signal
                Signal.handle((Signal) new Signal("INT"), signal -> {
                              ^
        MyLibrary.java:15: warning: Signal is internal proprietary API and may be removed in a future release
                Signal.handle((Signal) new Signal("INT"), signal -> {
                ^
        warning: Signal is internal proprietary API and may be removed in a future release
        MyLibrary.java:25: warning: Unsafe is internal proprietary API and may be removed in a future release
            private static final Unsafe UNSAFE = getUnsafe();
                                 ^
        MyLibrary.java:28: warning: Unsafe is internal proprietary API and may be removed in a future release
            private static Unsafe getUnsafe() {
                           ^
        MyLibrary.java:30: warning: Unsafe is internal proprietary API and may be removed in a future release
                    Field field = Unsafe.class.getDeclaredField("theUnsafe");
                                  ^
        MyLibrary.java:32: warning: Unsafe is internal proprietary API and may be removed in a future release
                    return (Unsafe) field.get(null);
                            ^
        Note: MyLibrary.java uses or overrides a deprecated API that is marked for removal.
        Note: Recompile with -Xlint:removal for details.
        11 warnings

        # Fixing the warning
        $ javac -Werror -Xlint:all -XDignore.symbol.file MyLibrary.java
        ...
        error: warnings found and -Werror specified
        ...
        1 error
        9 warnings
        [exit code failure]
        ```

        This shows multiple things:
        * These warnings are not actionable at least for sun.misc.Signal, which I filed separately as JDK-8349056. So one cannot just address those warnings as a solution.
        * These warnings are a lot of noise, in fact it's so much noise that it becomes very hard to find the actual useful warning in there (the redundant cast). So it hurts the usability of javac warnings significantly.
        * As far as I know these warnings cannot be suppressed or hidden to only see the relevant warnings.
        * BTW there are already deprecation warnings e.g. for sun.misc.Unsafe, so these warnings feel redundant/unnecessary.
        * javac -Werror has become unusable in any Java project using the sunc.misc.* APIs, therefore it is no longer possible to check in CI that there are no javac warnings in a project, if it uses sun.misc.Signal or any other sun.misc classes (as that causes javac to always error with exit code failed).

        I think these 'internal proprietary API' warnings should be removed, or be suppressible, so other actionable/useful warnings can still be seen and checked in CI automatically with -Werror.
        JDK-8332744 breaks the utility of javac warnings almost completely for any project using sun.misc.* classes (and so many projects do).

        Also from the description and comments on JDK-8332744 it's not clear whether it intended to emit these warnings in a non-suppressible way.

              cushon Liam Miller-Cushon
              bdaloze Benoit Daloze
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: