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

JavaFX Clipboard should not require AllPermission

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • 9
    • 8u51
    • javafx
    • x86
    • windows_8

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.8.0_51"
        Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
        Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Windows 7/8, MacOS X 10, Linux

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Java 8 update 51

        A DESCRIPTION OF THE PROBLEM :
        Technical information:

        The problem is related to class javafx.scene.input.Clipboard. The Method getSystemClipboard() contains request for all permissions and does not work without them. It's a bug - code should ask for "accessClipboard".

        Unfortunately, SAP code is not involved and we are not able to write workaround in our code to prevent this issue. Oracle's team should fix it inside the JavaFX class.


        Source code for related class:
        package javafx.scene.input;


        ...
            /**
             * Gets the current system clipboard, through which data can be stored and
             * retrieved. There is ever only one system clipboard for a JavaFX application.
             * @return The single system clipboard, used for cut / copy / paste operations
             */
            public static Clipboard getSystemClipboard() {
                try {
                    final SecurityManager securityManager = System.getSecurityManager();
                    if (securityManager != null) {
        --> securityManager.checkPermission(new AllPermission());
                    }
                    return getSystemClipboardImpl();
                } catch (final SecurityException e) {
                    return getLocalClipboardImpl();
                }
            }
        .....

        Stacktrace for call
        Daemon System Thread [JavaFX Application Thread] (Suspended (entry into method <init> in AllPermission))
                    AllPermission.<init>() line: 66 [local variables unavailable]
                    Clipboard.getSystemClipboard() line: 173
                    PasteboardImpl.<init>() line: 38
                    UtilitiesImpl.createPasteboard() line: 39
                    WCPasteboard.<clinit>() line: 43
                    WebPage.twkProcessKeyEvent(long, int, String, String, int, boolean, boolean, boolean, boolean) line: not available [native method]
                    WebPage.dispatchKeyEvent(WCKeyEvent) line: 737
                    WebView.processKeyEvent(KeyEvent) line: 1062
                    WebView.lambda$registerEventHandlers$31(KeyEvent) line: 1140
                    453037847.handle(Event) line: not available
                    CompositeEventHandler$NormalEventHandlerRecord<T>.handleBubblingEvent(T) line: 218
                    CompositeEventHandler<T>.dispatchBubblingEvent(Event) line: 80
                    EventHandlerManager.dispatchBubblingEvent(EventType<Event>, Event) line: 238
                    EventHandlerManager.dispatchBubblingEvent(Event) line: 191
                    NodeEventDispatcher(CompositeEventDispatcher).dispatchBubblingEvent(Event) line: 59
                    NodeEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 58
                    EventDispatchChainImpl.dispatchEvent(Event) line: 114
                    SceneEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 56
                    EventDispatchChainImpl.dispatchEvent(Event) line: 114
                    WindowEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 56
                    EventDispatchChainImpl.dispatchEvent(Event) line: 114
                    EventUtil.fireEventImpl(EventDispatchChain, EventTarget, Event) line: 74
                    EventUtil.fireEvent(EventTarget, Event) line: 54
                    Event.fireEvent(EventTarget, Event) line: 198
                    Scene$KeyHandler.process(KeyEvent) line: 3965
                    Scene$KeyHandler.access$1800(Scene$KeyHandler, KeyEvent) line: 3911
                    Scene.impl_processKeyEvent(KeyEvent) line: 2040
                    Scene$ScenePeerListener.keyEvent(KeyEvent) line: 2502
                    EmbeddedScene.lambda$null$297(int, char[], int, int) line: 305
                    1430468791.run() line: not available
                    AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
                    EmbeddedScene.lambda$keyEvent$298(int, char[], int, int) line: 291
                    438625584.run() line: not available
                    PlatformImpl.lambda$null$170(Runnable) line: 295
                    1760710214.run() line: not available
                    AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
                    PlatformImpl.lambda$runLater$171(Runnable, AccessControlContext) line: 294
                    770953327.run() line: not available
                    InvokeLaterDispatcher$Future.run() line: 95 [local variables unavailable]


        REGRESSION. Last worked in version 8u51

        ADDITIONAL REGRESSION INFORMATION:
        Lets check the getSystemClipboard() method in XToolkit class:

            public Clipboard getSystemClipboard() {
                SecurityManager security = System.getSecurityManager();
                if (security != null) {
                    security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
                }
                synchronized (this) {
                    if (clipboard == null) {
                        clipboard = new XClipboard("System", "CLIPBOARD");
                    }
                }
                return clipboard;
            }


        ***
        As You can see XToolkit is checking for
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Any test application with Swing JFrame + JFXPanel + FX inputField.

        Important is initialize SecurityManager without AllPermissions!

        try to copy/paste application from
        https://javafx-jira.kenai.com/browse/RT-38922

        but You need to add your own SecurityManager

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Correction in JavaFX Clipboard class

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        try to copy/paste application from
        https://javafx-jira.kenai.com/browse/RT-38922

        but You need to add your own SecurityManager
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Provide AllPermissions for your application.

        SUPPORT :
        YES

        Attachments

          Issue Links

            Activity

              People

                kcr Kevin Rushforth
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: