JDK-5086496 : REGRESSION: Can't copy/paste/cut in native components with an applet
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-08-13
  • Updated: 2006-01-19
  • Resolved: 2006-01-19
Related Reports
Duplicate :  
Description
Name: gm110360			Date: 08/12/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux jupiter 2.6.3-7mdk #1 Wed Mar 17 15:56:42 CET 2004 i686 unknown unknown GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Copy/Paste/Cut in *native* components no longer works in the presense of a SecurityManager which forbids access to the clipboard. Copying simply simply doesn't work while pasting throws a security exception. This seems to occur only if the dialog is modal, I would guess because the SecurityManager sees untrusted code on the stack (the show() or setVisible(true)) call.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached applet in the appletviewer.
2. Try pasting something into the text field via shift+insert or middle click.
3. Try copying from the text field with ctrl+insert or middle clicking.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Copying and pasting (and cutting) should work.
ACTUAL -
In step 2 (for shift+insert), an exception is thrown (stack trace attached).
Step 3 does nothing (pasting to a different X window doesn't produce the copied text).


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception stack trace from step 2:
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:582)
        at sun.awt.X11.ComponentAccessor.processEvent(ComponentAccessor.java:277)
        at sun.awt.X11.XTextFieldPeer.handleJavaKeyEvent(XTextFieldPeer.java:360)
        at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:614)
        at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:699)
        at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:916)
        at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:794)
        at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:632)
        at java.awt.Component.dispatchEventImpl(Component.java:3819)
        at java.awt.Component.dispatchEvent(Component.java:3781)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
        at java.awt.Dialog$1.run(Dialog.java:514)
        at java.awt.Dialog.show(Dialog.java:535)
        at TestApplet$1.windowOpened(TestApplet.java:25)
        at java.awt.Window.processWindowEvent(Window.java:1177)
        at java.awt.Window.processEvent(Window.java:1138)
        at java.awt.Component.dispatchEventImpl(Component.java:3933)
        at java.awt.Container.dispatchEventImpl(Container.java:2019)
        at java.awt.Window.dispatchEventImpl(Window.java:1764)
        at java.awt.Component.dispatchEvent(Component.java:3781)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
        at java.security.AccessController.checkPermission(AccessController.java:427)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
        at java.lang.SecurityManager.checkSystemClipboardAccess(SecurityManager.java:1368)
        at sun.awt.X11.XToolkit.getSystemClipboard(XToolkit.java:762)
        at sun.awt.X11.XTextTransferHelper.doClipboardAction(XTextTransferHelper.java:125)
        at sun.awt.X11.XTextTransferHelper.processKeyEvent(XTextTransferHelper.java:99)
        at sun.awt.X11.XTextFieldPeer$XAWTTextField.processComponentKeyEvent(XTextFieldPeer.java:641)
        at javax.swing.JComponent.processKeyEvent(JComponent.java:2680)
        at java.awt.Component.processEvent(Component.java:5242)
        at java.awt.Container.processEvent(Container.java:1961)
        ... 32 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Java code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class TestApplet extends Applet{
  
  public void start(){
    
    final Frame f = new Frame();
    f.setBounds(200, 200, 200, 100);
    f.addWindowListener(new WindowAdapter(){
      public void windowOpened(WindowEvent evt){
        Dialog dialog = new Dialog(f);
        Container contentPane = dialog;
        contentPane.setLayout(new BorderLayout());
        contentPane.add(new TextField());
        
        dialog.setModal(true);
        
        dialog.setBounds(200, 200, 200, 100);
    
        dialog.show();
      }
    });
    f.show();
  }
}


HTML code:
<APPLET code="TestApplet" WIDTH="200" HEIGHT="100"></APPLET>
---------- END SOURCE ----------

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 295945) 
======================================================================

Comments
EVALUATION BTW I could reproduce the issue only with Selection (using midle button) not with clipboard (SHIFT+INS)
16-10-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
18-08-2004

EVALUATION I have experimented with .java.policy file a little bit and found next behavior: 1. in jdk 1.4.2 operations with clipboard is allowed even if permissions in .java.policy are absent at all. 2. in jdk 1.5.0b51 operations with clipboard is allowed only if java.awt.AWTPermission.accessClipboard permission is present in .java.policy or PermitAll is set. ###@###.### 2004-08-13 I reproduced the problem using the tiger build 62 with XToolkit (which is default on Linux) as it's described in the comments section. This is XAWT-specific issue. The behavior was set with the fix for 4856343 (Problem with applet interaction with system selection clipboard). Indeed, if there is user code without the "accessClipboard" permission in the stack, access to the system clipboard/selection is forbidden. This issue concerning AWT text components may well be fixed along with 5054463 (XAWT text components should be rewritten without Swing usage). ###@###.### 2004-08-16 This issue does not seem to be highly visible (an AWT text component in a modal dialog). Committing to mustang. Note that Swing text components exhibit the same behavior (clipboard access is forbidden in modal dialogs) in 1.4.2 and 1.5.0 at least. ###@###.### 2004-08-17
17-08-2004