harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r522601 - in /harmony/enhanced/classlib/trunk/modules/swing: make/exclude.windows.x86.ibm src/main/java/common/javax/swing/TransferHandler.java src/test/api/java/common/javax/swing/TransferHandlerTest.java
Date Mon, 26 Mar 2007 19:17:53 GMT
Author: ayza
Date: Mon Mar 26 12:17:52 2007
New Revision: 522601

URL: http://svn.apache.org/viewvc?view=rev&rev=522601
Log:
Applying patch from HARMONY-3479 ([classlib][swing][netbeans] TransferHandler.getPasteAction().actionPerformed()
doesn't check if accessClipboard is allowed). TransferHandlerTest was removed from the exclude
list for IBM VME.

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/make/exclude.windows.x86.ibm
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/TransferHandler.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/TransferHandlerTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/make/exclude.windows.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/make/exclude.windows.x86.ibm?view=diff&rev=522601&r1=522600&r2=522601
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/make/exclude.windows.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/make/exclude.windows.x86.ibm Mon Mar 26
12:17:52 2007
@@ -2,7 +2,6 @@
 javax/swing/DefaultComboBoxModelTest.java
 javax/swing/JSpinnerTest.java
 javax/swing/Timer_MultithreadedTest.java
-javax/swing/TransferHandlerTest.java
 javax/swing/border/CompoundBorderTest.java
 javax/swing/border/EtchedBorderTest.java
 javax/swing/border/LineBorderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/TransferHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/TransferHandler.java?view=diff&rev=522601&r1=522600&r2=522601
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/TransferHandler.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/TransferHandler.java
Mon Mar 26 12:17:52 2007
@@ -57,10 +57,11 @@
         public void actionPerformed(final ActionEvent e) {
             Object source = e.getSource();
             TransferHandler transferHandler = getTransferHandler(source);
-            if (transferHandler != null) {
-                transferHandler.exportToClipboard((JComponent)source,
-                                                  getSystemClipboard(),
-                                                  MOVE);
+            Clipboard clipboard = getSystemClipboard();
+
+            if ((transferHandler != null) && (clipboard != null)) {
+                transferHandler.exportToClipboard(
+                        (JComponent) source, clipboard, MOVE);
             }
         }
     };
@@ -70,10 +71,11 @@
         public void actionPerformed(final ActionEvent e) {
             Object source = e.getSource();
             TransferHandler transferHandler = getTransferHandler(source);
-            if (transferHandler != null) {
-                transferHandler.exportToClipboard((JComponent)source,
-                                                  getSystemClipboard(),
-                                                  COPY);
+            Clipboard clipboard = getSystemClipboard();
+
+            if ((transferHandler != null) && (clipboard != null)) {
+                transferHandler.exportToClipboard(
+                        (JComponent) source, clipboard, COPY);
             }
         }
     };
@@ -83,10 +85,13 @@
         public void actionPerformed(final ActionEvent e) {
             Object source = e.getSource();
             TransferHandler transferHandler = getTransferHandler(source);
-            if (transferHandler != null) {
-               Transferable t = getSystemClipboard().getContents(this);
+            Clipboard clipboard = getSystemClipboard();
+
+            if ((transferHandler != null) && (clipboard != null)) {
+               Transferable t = clipboard.getContents(this);
+
                if (t != null) {
-                   transferHandler.importData((JComponent)source, t);
+                   transferHandler.importData((JComponent) source, t);
                }
             }
         }
@@ -147,7 +152,13 @@
     }
 
     private static Clipboard getSystemClipboard() {
-        return Toolkit.getDefaultToolkit().getSystemClipboard();
+        try {
+            return Toolkit.getDefaultToolkit().getSystemClipboard();
+        } catch (SecurityException e) {
+            // we need to catch this exception in order to be compatible with RI
+            // see HARMONY-3479
+            return null;
+        }
     }
 
     private PropertyDescriptor getPropertyDescriptor(final JComponent c) {
@@ -309,5 +320,6 @@
         return COPY_ACTION;
     }
 }
+
 
 

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/TransferHandlerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/TransferHandlerTest.java?view=diff&rev=522601&r1=522600&r2=522601
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/TransferHandlerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/TransferHandlerTest.java
Mon Mar 26 12:17:52 2007
@@ -20,15 +20,19 @@
  */
 package javax.swing;
 
+import java.awt.AWTPermission;
 import java.awt.Color;
 import java.awt.datatransfer.Clipboard;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.StringSelection;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
 import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.io.IOException;
+import java.security.Permission;
+
 
 public class TransferHandlerTest extends SwingTestCase {
     TransferHandler transferHandler;
@@ -264,5 +268,45 @@
         //        assertEquals(button, trH.component);
         //        assertEquals("copy", action.getValue(Action.NAME));
         //        assertTrue(action == TransferHandler.getCopyAction());
+    }
+
+    public void testAccessSystemClipboard() {
+        // Regression test for HARMONY-3479
+
+        class TestSecurityManager extends SecurityManager {
+
+            public boolean flag;
+
+            public void checkPermission(Permission perm) {
+                if ((perm instanceof AWTPermission)
+                        && "accessClipboard".equals(perm.getName())) {
+                    flag = true;
+                    throw new SecurityException("test");
+                }
+            }
+        }
+
+        SecurityManager oldSecurityManager = System.getSecurityManager();
+        TestSecurityManager testSecurityManager = new TestSecurityManager();
+        System.setSecurityManager(testSecurityManager);
+
+        try {
+            ActionEvent event = new ActionEvent(new JPanel(), 0, "");
+            Action action;
+
+            testSecurityManager.flag = false;
+            TransferHandler.getCopyAction().actionPerformed(event);
+            assertTrue(testSecurityManager.flag);
+
+            testSecurityManager.flag = false;
+            TransferHandler.getCutAction().actionPerformed(event);
+            assertTrue(testSecurityManager.flag);
+
+            testSecurityManager.flag = false;
+            TransferHandler.getPasteAction().actionPerformed(event);
+            assertTrue(testSecurityManager.flag);
+        } finally {
+            System.setSecurityManager(oldSecurityManager);
+        }
     }
 }



Mime
View raw message