8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit
authorazvegint
Wed, 28 Sep 2016 03:40:45 +0300
changeset 41402 9ff91b2cd7a7
parent 41401 14cf712458c8
child 41403 be56daafbeaa
8164536: enableSuddenTermination() - Not throws SecurityException if a security manager exists and it will not allow the caller to invoke System.exit Reviewed-by: serb, ssadetsky
jdk/src/java.desktop/share/classes/java/awt/Desktop.java
jdk/src/java.desktop/share/classes/java/awt/Taskbar.java
--- a/jdk/src/java.desktop/share/classes/java/awt/Desktop.java	Tue Sep 27 14:12:48 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/java/awt/Desktop.java	Wed Sep 28 03:40:45 2016 +0300
@@ -271,6 +271,14 @@
         }
     }
 
+    private void checkEventsProcessingPermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(new RuntimePermission(
+                    "canProcessApplicationEvents"));
+        }
+    }
+
     /**
      * Returns the {@code Desktop} instance of the current
      * desktop context. On some platforms the Desktop API may not be
@@ -662,7 +670,7 @@
      *
      * @throws SecurityException if a security manager exists and it
      * denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
+     * {@code RuntimePermission("canProcessApplicationEvents")}
      * permission
      *
      * @see java.awt.desktop.AppForegroundListener
@@ -674,7 +682,7 @@
      * @since 9
      */
     public void addAppEventListener(final SystemEventListener listener) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         peer.addAppEventListener(listener);
     }
 
@@ -689,7 +697,7 @@
      *
      * @throws SecurityException if a security manager exists and it
      * denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
+     * {@code RuntimePermission("canProcessApplicationEvents")}
      * permission
      *
      * @see java.awt.desktop.AppForegroundListener
@@ -701,7 +709,7 @@
      * @since 9
      */
     public void removeAppEventListener(final SystemEventListener listener) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         peer.removeAppEventListener(listener);
     }
 
@@ -716,7 +724,7 @@
      *
      * @throws SecurityException if a security manager exists and it
      * denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
+     * {@code RuntimePermission("canProcessApplicationEvents")}
      * permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_ABOUT} action
@@ -724,7 +732,7 @@
      * @since 9
      */
     public void setAboutHandler(final AboutHandler aboutHandler) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkActionSupport(Action.APP_ABOUT);
         peer.setAboutHandler(aboutHandler);
     }
@@ -741,14 +749,13 @@
      *
      * @throws SecurityException if a security manager exists and it
      * denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
-     * permission
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_PREFERENCES} action
      * @since 9
      */
     public void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkActionSupport(Action.APP_PREFERENCES);
         peer.setPreferencesHandler(preferencesHandler);
     }
@@ -770,7 +777,7 @@
      * @throws SecurityException if a security manager exists and its
      * {@link java.lang.SecurityManager#checkRead(java.lang.String)}
      * method denies read access to the files, or it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
+     * {@code RuntimePermission("canProcessApplicationEvents")}
      * permission, or the calling thread is not allowed to create a
      * subprocess
      * @throws UnsupportedOperationException if the current platform
@@ -778,7 +785,7 @@
      * @since 9
      */
     public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkExec();
         checkRead();
         checkActionSupport(Action.APP_OPEN_FILE);
@@ -800,12 +807,14 @@
      * @param printFileHandler handler
      * @throws SecurityException if a security manager exists and its
      * {@link java.lang.SecurityManager#checkPrintJobAccess()} method denies
-     * the permission to print.
+     * the permission to print or it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_PRINT_FILE} action
      * @since 9
      */
     public void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
+        checkEventsProcessingPermission();
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             sm.checkPrintJobAccess();
@@ -832,7 +841,7 @@
      *
      * @param openURIHandler handler
      *
-     * {@code AWTPermission("showWindowWithoutWarningBanner")}
+     * {@code RuntimePermission("canProcessApplicationEvents")}
      * permission, or the calling thread is not allowed to create a
      * subprocess
      * @throws UnsupportedOperationException if the current platform
@@ -840,7 +849,7 @@
      * @since 9
      */
     public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkExec();
         checkActionSupport(Action.APP_OPEN_URI);
         peer.setOpenURIHandler(openURIHandler);
@@ -856,12 +865,14 @@
      * asked to quit
      *
      * @throws SecurityException if a security manager exists and it
-     * will not allow the caller to invoke {@code System.exit}
+     * will not allow the caller to invoke {@code System.exit} or it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_QUIT_HANDLER} action
      * @since 9
      */
     public void setQuitHandler(final QuitHandler quitHandler) {
+        checkEventsProcessingPermission();
         checkQuitPermission();
         checkActionSupport(Action.APP_QUIT_HANDLER);
         peer.setQuitHandler(quitHandler);
@@ -874,13 +885,15 @@
      * @param strategy the way this application should be shutdown
      *
      * @throws SecurityException if a security manager exists and it
-     * will not allow the caller to invoke {@code System.exit}
+     * will not allow the caller to invoke {@code System.exit} or it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_QUIT_STRATEGY} action
      * @see QuitStrategy
      * @since 9
      */
     public void setQuitStrategy(final QuitStrategy strategy) {
+        checkEventsProcessingPermission();
         checkQuitPermission();
         checkActionSupport(Action.APP_QUIT_STRATEGY);
         peer.setQuitStrategy(strategy);
@@ -901,13 +914,15 @@
      * effectively "kill -KILL" your application.
      *
      * @throws SecurityException if a security manager exists and it
-     * will not allow the caller to invoke {@code System.exit}
+     * will not allow the caller to invoke {@code System.exit} or it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
      * @see #disableSuddenTermination()
      * @since 9
      */
     public void enableSuddenTermination() {
+        checkEventsProcessingPermission();
         checkQuitPermission();
         checkActionSupport(Action.APP_SUDDEN_TERMINATION);
         peer.enableSuddenTermination();
@@ -920,13 +935,15 @@
      * may not be terminated without notification.
      *
      * @throws SecurityException if a security manager exists and it
-     * will not allow the caller to invoke {@code System.exit}
+     * will not allow the caller to invoke {@code System.exit} or it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_SUDDEN_TERMINATION} action
      * @see #enableSuddenTermination()
      * @since 9
      */
     public void disableSuddenTermination() {
+        checkEventsProcessingPermission();
         checkQuitPermission();
         checkActionSupport(Action.APP_SUDDEN_TERMINATION);
         peer.disableSuddenTermination();
@@ -938,13 +955,13 @@
      * @param allWindows if all windows of this application should be moved to
      * the foreground, or only the foremost one
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_REQUEST_FOREGROUND} action
      * @since 9
      */
     public void requestForeground(final boolean allWindows) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkActionSupport(Action.APP_REQUEST_FOREGROUND);
         peer.requestForeground(allWindows);
     }
@@ -957,13 +974,13 @@
      * and registered in the Info.plist with CFBundleHelpBookFolder
      *
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_HELP_VIEWER} action
      * @since 9
      */
     public void openHelpViewer() {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkActionSupport(Action.APP_HELP_VIEWER);
         peer.openHelpViewer();
     }
@@ -975,13 +992,13 @@
      *
      * @param menuBar to use when no other frames are active
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Desktop.Action#APP_MENU_BAR} action
      * @since 9
      */
     public void setDefaultMenuBar(final JMenuBar menuBar) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkActionSupport(Action.APP_MENU_BAR);
         peer.setDefaultMenuBar(menuBar);
     }
--- a/jdk/src/java.desktop/share/classes/java/awt/Taskbar.java	Tue Sep 27 14:12:48 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/java/awt/Taskbar.java	Wed Sep 28 03:40:45 2016 +0300
@@ -179,14 +179,13 @@
 
     /**
      *  Calls to the security manager's {@code checkPermission} method with
-     *  an {@code AWTPermission("showWindowWithoutWarningBanner")}
-     *  permission.
+     *  an {@code RuntimePermission("canProcessApplicationEvents")} permissions.
      */
-    private void checkAWTPermission(){
+    private void checkEventsProcessingPermission(){
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
-            sm.checkPermission(new AWTPermission(
-                    "showWindowWithoutWarningBanner"));
+            sm.checkPermission(new RuntimePermission(
+                    "canProcessApplicationEvents"));
         }
     }
 
@@ -262,12 +261,12 @@
      * @param enabled disables this request if false
      * @param critical if this is an important request
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#USER_ATTENTION} feature
      */
     public void requestUserAttention(final boolean enabled, final boolean critical) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.USER_ATTENTION);
         peer.requestUserAttention(enabled, critical);
     }
@@ -277,12 +276,12 @@
      *
      * @param w window
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#USER_ATTENTION_WINDOW} feature
      */
     public void requestWindowUserAttention(Window w) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.USER_ATTENTION_WINDOW);
         peer.requestWindowUserAttention(w);
     }
@@ -293,12 +292,12 @@
      *
      * @param menu the PopupMenu to attach to this application
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#MENU} feature
      */
     public void setMenu(final PopupMenu menu) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.MENU);
         peer.setMenu(menu);
     }
@@ -308,12 +307,12 @@
      *
      * @return the PopupMenu
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#MENU} feature
      */
     public PopupMenu getMenu() {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.MENU);
         return peer.getMenu();
     }
@@ -323,12 +322,12 @@
      *
      * @param image to change
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
      */
     public void setIconImage(final Image image) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.ICON_IMAGE);
         peer.setIconImage(image);
     }
@@ -338,12 +337,12 @@
      *
      * @return an image of this application's icon
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
      */
     public Image getIconImage() {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.ICON_IMAGE);
         return peer.getIconImage();
     }
@@ -360,13 +359,13 @@
      * Passing {@code null} as parameter hides the badge.
      * @param badge label to affix to the icon
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#ICON_BADGE_NUMBER}
      * or {@link Taskbar.Feature#ICON_BADGE_TEXT} feature
      */
     public void setIconBadge(final String badge) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.ICON_BADGE_NUMBER);
         peer.setIconBadge(badge);
     }
@@ -379,12 +378,12 @@
      * @param w window to update
      * @param badge image to affix to the icon
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#ICON_BADGE_IMAGE_WINDOW} feature
      */
     public void setWindowIconBadge(Window w, final Image badge) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.ICON_BADGE_IMAGE_WINDOW);
         if (w != null) {
             peer.setWindowIconBadge(w, badge);
@@ -396,11 +395,13 @@
      * Affixes a small system-provided progress bar to this application's icon.
      *
      * @param value from 0 to 100, other to disable progress indication
+     * @throws SecurityException if a security manager exists and it denies the
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE} feature
      */
     public void setProgressValue(int value) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.PROGRESS_VALUE);
         peer.setProgressValue(value);
     }
@@ -411,12 +412,12 @@
      * @param w window to update
      * @param value from 0 to 100, other to disable progress indication
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE_WINDOW} feature
      */
     public void setWindowProgressValue(Window w, int value) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.PROGRESS_VALUE_WINDOW);
         if (w != null) {
             peer.setWindowProgressValue(w, value);
@@ -434,12 +435,12 @@
      * @see State#INDETERMINATE
      * @see State#ERROR
      * @throws SecurityException if a security manager exists and it denies the
-     * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.
+     * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
      * does not support the {@link Taskbar.Feature#PROGRESS_STATE_WINDOW} feature
      */
     public void setWindowProgressState(Window w, State state) {
-        checkAWTPermission();
+        checkEventsProcessingPermission();
         checkFeatureSupport(Feature.PROGRESS_STATE_WINDOW);
         if (w != null) {
             peer.setWindowProgressState(w, state);