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

Stage.alwaysOnTop() doesn't work if a security manager is set

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u45, 9
    • Fix Version/s: 9
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Backports

        Description

        FULL PRODUCT VERSION :
        1.8.0_45

        ADDITIONAL OS VERSION INFORMATION :
        Windows 6.1.7601

        A DESCRIPTION OF THE PROBLEM :
        If using a JFXPanel withing a Swing application, setting "alwaysOnTop" to true for a Stage does not work if a security manager has been set, even if that manager does not restrict any permissions. This doesn't seem to be an issue with pure JavaFX applications, and it works fine if no security manager is set

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the code attached and click the "Show Alert" button in the popup window

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The alert that pops up should be always on top of any other window
        ACTUAL -
        The alert can be hidden by any other window including the man application window. If however the first in in the main() method (which sets the DoNothingSecurityManager) is commented out the alert will always be on top

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.io.FileDescriptor;
        import java.net.InetAddress;
        import java.security.Permission;
        import javax.swing.*;

        import javafx.application.Platform;
        import javafx.embed.swing.JFXPanel;
        import javafx.scene.Group;
        import javafx.scene.Scene;
        import javafx.scene.control.Alert;
        import javafx.scene.control.Button;
        import javafx.stage.Stage;

        public class JFXPanelAlwaysOnTopDialogTest {

          public static void main(String[] args) {
            System.setSecurityManager(new DoNothingSecurityManager());
            SwingUtilities.invokeLater(JFXPanelAlwaysOnTopDialogTest::initAndShowUI);
          }

          private static void initAndShowUI() {
            JFrame frame = new JFrame("Test");
            JFXPanel jfxPanel = new JFXPanel();
            frame.add(jfxPanel);
            frame.setSize(100, 100);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            Platform.runLater(() -> initFX(jfxPanel));
          }

          private static void initFX(JFXPanel jfxPanel) {
            Button button = new Button("Show Alert");
            button.setOnAction(event -> showAlert());
            Group root = new Group(button);
            jfxPanel.setScene(new Scene(root));
          }

          private static void showAlert() {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            Stage stage = (Stage)alert.getDialogPane().getScene().getWindow();
            stage.setAlwaysOnTop(true);
            alert.setContentText("Here is my alert");
            alert.showAndWait();
          }

          private static class DoNothingSecurityManager extends SecurityManager {

            public void checkPermission(Permission perm) {}
            public void checkPermission(Permission perm, Object context) {}
            public void checkCreateClassLoader() {}
            public void checkAccess(Thread t) {}
            public void checkAccess(ThreadGroup g) {}
            public void checkExit(int status) {}
            public void checkExec(String cmd) {}
            public void checkLink(String lib) {}
            public void checkRead(FileDescriptor fd) {}
            public void checkRead(String file) {}
            public void checkRead(String file, Object context) {}
            public void checkWrite(FileDescriptor fd) {}
            public void checkWrite(String file) {}
            public void checkDelete(String file) {}
            public void checkConnect(String host, int port) {}
            public void checkConnect(String host, int port, Object context) {}
            public void checkListen(int port) {}
            public void checkAccept(String host, int port) {}
            public void checkMulticast(InetAddress maddr) {}
            public void checkPropertiesAccess() {}
            public void checkPropertyAccess(String key) {}
            public boolean checkTopLevelWindow(Object window) {
              return true;
            }
            public void checkPrintJobAccess() {}
            public void checkSystemClipboardAccess() {}
            public void checkAwtEventQueueAccess() {}
            public void checkPackageAccess(String pkg) {}
            public void checkPackageDefinition(String pkg) {}
            public void checkSetFactory() {}
            public void checkMemberAccess(Class<?> clazz, int which) {}
            public void checkSecurityAccess(String target) {}
          }
        }

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  kcr Kevin Rushforth
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: