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

[macos] All Swing/AWT apps cause Allow Notifications prompt to appear when app is launched

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b21
    • CPU:
      x86_64
    • OS:
      os_x
    • Verification:
      Verified

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        MacOS 10.15.7
        OpenJDK 11.0.9 and 16.0.0 (but not on 9.0.7.1).

        A DESCRIPTION OF THE PROBLEM :
        After the implementation of JDK-8187639, all Swing/AWT apps now cause the following prompt to appear on MacOS when the app is first launched:

        "java" Notifications
        Notifications may include alerts, sounds, and icon badges.
        Don't Allow/Allow?

        The prompt confuses/annoys users, since our app should not be causing any notifications to happen.

        The bug appears to have been introduced with JDK-8187639. I believe the permission popup appears in response to the following call in src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m:
        [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];

        I managed to cause a similar permission popup to appear from a standalone Objective-C app that just performs the call above. So this seems likely to be the cause.

        The suggested fix is to only call NSUserNotificationCenter.setDelegate if the TrayIcon facility is actually used, i.e. in src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m instead of always when the native Toolkit is being initialized.


        REGRESSION : Last worked in version 8

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1) Open "System Preferences" and then the "Notifications" pane. If there is any entry or entries for "java" in the panel to the left, select each entry and press the Delete key (Fn+Backspace) to reset the notification prompt, to ensure that it pops up in the next step.
        2) Run the attached trivial AWT app, which just calls Toolkit.getDefaultToolkit(). Any Swing or AWT action would work.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The app should exit uneventfully, with no user-visible permission popup.
        ACTUAL -
        An OS-level prompt pops up, asking the user to permit notifications from "java".

        ---------- BEGIN SOURCE ----------
        import java.awt.Toolkit;
         
        public class SpuriousNotificationExhibit {
          public static final void main(String args[]) throws Exception {
            // Any Swing or AWT action which would cause the toolkit to be initialized would work here.
            Toolkit.getDefaultToolkit();
          }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        No workaround exists. Though obviously the user can click away the popup.

        FREQUENCY : always


          Attachments

            Issue Links

              Activity

                People

                Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: