-
Bug
-
Resolution: Fixed
-
P3
-
24
-
b10
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8350017 | 24.0.2 | Liam Miller-Cushon | P3 | Resolved | Fixed | b01 |
JDK-8350299 | 24.0.1 | Nibedita Jena | P3 | Resolved | Fixed | b07 |
```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
* 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.
Also from the description and comments on
- backported by
-
JDK-8350017 'internal proprietary API' warnings make javac warnings unusable
-
- Resolved
-
-
JDK-8350299 'internal proprietary API' warnings make javac warnings unusable
-
- Resolved
-
- caused by
-
JDK-8332744 [REDO] 'internal proprietary API' diagnostics if --system is configured to an earlier JDK version
-
- Resolved
-
- relates to
-
JDK-8349848 Support lint control of sunapi diagnostics
-
- Closed
-
-
JDK-8349846 [REDO] [REDO] 'internal proprietary API' diagnostics if --system is configured to an earlier JDK version
-
- Open
-
-
JDK-8349056 internal proprietary API warnings for sun.misc.Signal are not actionable
-
- Closed
-
- links to
-
Commit(master) openjdk/jdk24u/754e5ddb
-
Commit(master) openjdk/jdk/1ab1c1d5
-
Review(master) openjdk/jdk24u/69
-
Review(master) openjdk/jdk/23448