JDK-8349056 : internal proprietary API warnings for sun.misc.Signal are not actionable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,24
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2025-01-30
  • Updated: 2025-02-17
  • Resolved: 2025-02-17
Related Reports
Causes :  
Duplicate :  
Relates :  
Relates :  
Description
Using this small reproducer:
```java
import sun.misc.Signal;

public class MyLibraryWithSignal {

    public static void main(String[] args) throws InterruptedException {
        Signal.handle(new Signal("INT"), signal -> {
            // Imagine some more useful signal handler, just keeping the example short here
            System.out.println("Goodbye!");
            System.exit(0);
        });

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

}
```

Compiling it with javac gives:
```
$ javac -Xlint:all MyLibraryWithSignal.java        
MyLibraryWithSignal.java:1: warning: Signal is internal proprietary API and may be removed in a future release
import sun.misc.Signal;
               ^
MyLibraryWithSignal.java:6: warning: Signal is internal proprietary API and may be removed in a future release
        Signal.handle(new Signal("INT"), signal -> {
                          ^
MyLibraryWithSignal.java:6: warning: Signal is internal proprietary API and may be removed in a future release
        Signal.handle(new Signal("INT"), signal -> {
        ^
warning: Signal is internal proprietary API and may be removed in a future release
4 warnings
```

The principle of warnings is for them to be actionable, to tell people seeing them to do something about it.

But what can a user using sun.misc.Signal do?
* They cannot just stop using it, that breaks useful functionality. There is no replacement API that can be used instead.
* Being the only Java API available to use signals it is the one used by many projects. The fact it's under `sun.misc` is basically just legacy. It cannot be called "internal proprietary API" given the usage of it today (by many projects and being supported even on non-HotSpot).
* sun.misc.Signal is widely used, e.g. https://github.com/search?q=sun.misc.Signal&type=code
* The warning cannot be suppressed as far as I can tell. -XDignore.symbol.file used to suppress it, but no longer has that effect. This got addressed JDK-8349058, but still the problem is there: there is a warning which the user cannot do anything about except suppressing it, i.e. it cannot be addressed.
* Asking each Java project to reimplement Signal with JNI (far from trivial, need to ship a native library, can lead to subtle bugs in interactions with how the JDK uses signals) seems unreasonable and in fact running against the goals of integrity by default.

Is therefore the only way to address these warnings to use jdk.internal.misc.Signal instead? I would think that's not a good solution.

I think these warnings for sun.misc.Signal should be removed (nothing can be done about them), warnings should be added when a replacement is available, something like java.util.Signal or so.
Comments
[~bdaloze] There isn't a JEP to track at this time. There were a number of prototypes but paused right now as there are higher priority features that will benefit a far greater number of developers and libraries. So I can't say what a future Signal API might look like. In the mean-time there is no plan to remove the existing undocumented API. If you are looking to do your own signal handling on non-Windows platforms then the signal chaining facility / interposer still exists in order to coordinate signal usage with the VM. It isn't magically used when using FFM to call sigaction or other functions so there is some setup and plumbing required if you are looking to do the equivalent of the Signal Dispatcher.
17-02-2025

> Ultimately I want to ensure that sun.misc.Signal is not removed (nor deprecated with deprecation warnings) before there is a replacement. The only assurances are that the JDK evolves according to the processes described in the various Process JEPs or according to the JDK's "common law", and that at any point, the JDK Lead prioritises activities based on the perceived utility they offer the Java user community taken as a whole, while trying to balance the frequent conflicting needs different users may have. I am not aware of any JDK process mechanism that would allow anyone to ensure ahead of time what you want to ensure, which may or may not contradict what other people may like to ensure.
17-02-2025

Essentially a duplicate of JDK-8087286.
17-02-2025

[~alanb] Is there a canonical issue tracking adding a proper API for Signal? I think https://bugs.openjdk.org/browse/JDK-8087286 is the closest I found, I'll close in favor of that and leave a comment there. I found https://bugs.openjdk.org/browse/BKLG-1300 but that seems on a different tracker which sounds like /dev/null, yet this is still a relevant issue. Ultimately I want to ensure that sun.misc.Signal is not removed (nor deprecated with deprecation warnings) before there is a replacement. Because doing so would result in a big mess, an effectively breaking change, and likely less safety than before (as explained in description & earlier comments). The recent deprecation of Unsafe off-heap methods with incomplete replacements (won't expand on that here) is not giving me a lot of confidence. I also think having (sun API) warnings for like 10 years without a replacement is not meaningful, hence I think there should be no warnings for sun.misc.Signal since it is the de facto API for handling signals in the JDK. Could you reply to my "Could you elaborate? Does it mean using FFM to call signal/sigaction automatically use native signal chaining?" question? "The interaction with FFM and the signal chaining library are understood." is not clear.
17-02-2025

This issue should be closed, it's not helpful to keep it open. The temporary regression with -XDignore.symbol.file has been fixed. The undocumented/unsupported APIs in jdk.unsupported have no future. It's a feature, not a bug, that javac generates a warning when compiling code that uses classes from this module. An API for handling control-C and other signals is lower priority right now compared to the other investments that will significantly advance the Java Platform.
16-02-2025

As originally submitted, the issue was about the inability to suppress a certain warning. It's our understanding that that's a duplicate of JDK-8332744, which has been fixed. If you want to debate the principle, I will say this: > The principle of warnings is for them to be actionable, to tell people seeing them to do something about it. Sometimes a warning is issued to alert the developer to a significant tradeoff they face, and what they do about it is decide what tradeoff they choose. In this case, since the JDK offers no (standard) API for signal handling, the developer can either not rely on the functionality or provide the functionality by relying on JDK internals. Doing the latter means aknowledging that the code is not portable and not subject to any backward compatibility guarantees, and therefore the developer accepts a higher maintenance burden. Since the developer can now suppress the warning, it is actionable — the developer either uses the internal class and accepts the additional burden of maintaining non-portable code or not. Because sun.misc.Signal is not an API offered by the JDK, and is therefore not subject to backward compatibility, its use must be warned to alert the developer to the significance of using that internal class. Requesting that the JDK offer an API for signal handling is a separate issue.
14-02-2025

> An API was proposed for JDK 9 but had to be withdrawn. Exploration and prototyping since did not come to a consensus, so paused for now as there is many other higher priority things to work on. What about moving the existing API to some proper package? Time and usages have proven it's a good enough API and it's pretty small, i.e. it works. Do you have any link to these older efforts? I have searched with https://bugs.openjdk.org/browse/JDK-8087286?jql=project%20%3D%20JDK%20AND%20text%20~%20%22sun.misc.Signal%20replacement%22 but that didn't give much. > The interaction with FFM and the signal chaining library are understood. Could you elaborate? Does it mean using FFM to call signal/sigaction automatically use native signal chaining? In any case reimplementing sun.misc.Signal using FFM or JNI seems a lot of work, and not something we would want every library using sun.misc.Signal to do. Notably one cannot call Java code from a native signal handler, so there needs to be an extra Java Thread to actually run the handlers, and some async-signal-safe way to communicate between the native signal handler and that Java Thread (so e.g. I don't think FFM is enough for this), etc. i.e. for the safety of the JVM it's far safer if a Signal API is provided rather than expecting third-party library to reimplement such a tricky part.
14-02-2025

[~alanb] No, it's not, it's independent. Regardless of whether sun api warnings can be suppressed it's bad to warn for sun.misc.Signal since there is no replacement. The solution is to add a replacement for sun.misc.Signal, or never warn for it. Notably https://bugs.openjdk.org/browse/JDK-8349846 mentions this as "Some of the remaining uses of APIs that result in warnings to not have easy migration paths (JDK-8349056).".
14-02-2025

This issue was originally `javac -Xlint:all -XDignore.symbol.file MyLibraryWithSignal`. The warnings printed by that command seem to be a temporary regression caused by JDK-8332744 (a redo of 8331081), and addressed by JDK-8349058 in main line and jdk24u. I see this issue has been reopened and changed so it's now more of a complaint about the warnings when compiling code that uses APIs from the jdk.unsupported module. The undocumented APIs in this module are the so-called "Critical internal APIs" listed in JEP 260. It is true that there isn't a clear roadmap at this time for standard API for signals handing. An API was proposed for JDK 9 but had to be withdrawn. Exploration and prototyping since did not come to a consensus, so paused for now as there is many other higher priority things to work on. The interaction with FFM and the signal chaining library are understood. The lack of a roadmap for a standard API does not take from the point that the sun.misc.* APIs were never a documented/supported interface. The warning has been there for a long time, including JDK 8, and probably back to JDK 6 when the symbol file was introduced.
14-02-2025

Is this a dup of JDK-8349058 ?
13-02-2025