# HG changeset patch # User pchelko # Date 1389625764 -14400 # Node ID d68cbf54738f42c8b9848e5f478f8a631acb3bb1 # Parent 5bf4d2bd28f18e43fd862ab52d913c934d642fe8 8029893: Remove reflection from DataTransferer.getInstance Reviewed-by: anthony, serb diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java Mon Jan 13 19:09:24 2014 +0400 @@ -89,7 +89,7 @@ private static CDataTransferer fTransferer; - public static synchronized CDataTransferer getInstanceImpl() { + static synchronized CDataTransferer getInstanceImpl() { if (fTransferer == null) { fTransferer = new CDataTransferer(); } diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Mon Jan 13 19:09:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ import java.net.MalformedURLException; import sun.awt.*; +import sun.awt.datatransfer.DataTransferer; import sun.lwawt.*; import sun.lwawt.LWWindowPeer.PeerType; import sun.security.action.GetBooleanAction; @@ -112,8 +113,6 @@ private static final boolean inAWT; public LWCToolkit() { - SunToolkit.setDataTransfererClassName("sun.lwawt.macosx.CDataTransferer"); - areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true")); //set system property if not yet assigned System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); @@ -442,6 +441,11 @@ } @Override + public DataTransferer getDataTransferer() { + return CDataTransferer.getInstanceImpl(); + } + + @Override public boolean isAlwaysOnTopSupported() { return true; } diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java --- a/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java Mon Jan 13 19:09:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -570,7 +570,7 @@ if (DataTransferer.isFlavorCharsetTextType(this) && (isRepresentationClassInputStream() || isRepresentationClassByteBuffer() || - DataTransferer.byteArrayClass.equals(representationClass))) + byte[].class.equals(representationClass))) { params += ";charset=" + DataTransferer.getTextCharset(this); } @@ -1015,7 +1015,7 @@ !(isRepresentationClassReader() || String.class.equals(representationClass) || isRepresentationClassCharBuffer() || - DataTransferer.charArrayClass.equals(representationClass))) + char[].class.equals(representationClass))) { String thisCharset = DataTransferer.canonicalName(getParameter("charset")); @@ -1100,8 +1100,7 @@ !(isRepresentationClassReader() || String.class.equals(representationClass) || isRepresentationClassCharBuffer() || - DataTransferer.charArrayClass.equals - (representationClass))) + char[].class.equals(representationClass))) { String charset = DataTransferer.canonicalName(getParameter("charset")); diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/share/classes/sun/awt/HToolkit.java --- a/jdk/src/share/classes/sun/awt/HToolkit.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/share/classes/sun/awt/HToolkit.java Mon Jan 13 19:09:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,8 @@ package sun.awt; +import sun.awt.datatransfer.DataTransferer; + import java.awt.*; import java.awt.dnd.*; import java.awt.dnd.peer.DragSourceContextPeer; @@ -184,6 +186,11 @@ return false; } + @Override + public DataTransferer getDataTransferer() { + return null; + } + public GlobalCursorManager getGlobalCursorManager() throws HeadlessException { throw new HeadlessException(); diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/share/classes/sun/awt/SunToolkit.java --- a/jdk/src/share/classes/sun/awt/SunToolkit.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/share/classes/sun/awt/SunToolkit.java Mon Jan 13 19:09:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,6 +46,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import sun.awt.datatransfer.DataTransferer; import sun.security.util.SecurityConstants; import sun.util.logging.PlatformLogger; import sun.misc.SoftCache; @@ -203,6 +204,8 @@ public abstract boolean isTraySupported(); + public abstract DataTransferer getDataTransferer(); + @SuppressWarnings("deprecation") public abstract FontPeer getFontPeer(String name, int style); @@ -1191,19 +1194,6 @@ return getStartupLocale(); } - private static String dataTransfererClassName = null; - - protected static void setDataTransfererClassName(String className) { - dataTransfererClassName = className; - } - - public static String getDataTransfererClassName() { - if (dataTransfererClassName == null) { - Toolkit.getDefaultToolkit(); // transferer set during toolkit init - } - return dataTransfererClassName; - } - // Support for window closing event notifications private transient WindowClosingListener windowClosingListener = null; /** diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java --- a/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java Fri Jan 10 12:07:29 2014 +0400 +++ b/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java Mon Jan 13 19:09:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,10 @@ package sun.awt.datatransfer; -import java.awt.AWTError; import java.awt.EventQueue; +import java.awt.Graphics; import java.awt.Image; -import java.awt.Graphics; +import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.FlavorMap; @@ -138,16 +138,6 @@ public abstract class DataTransferer { /** - * Cached value of Class.forName("[C"); - */ - public static final Class charArrayClass; - - /** - * Cached value of Class.forName("[B"); - */ - public static final Class byteArrayClass; - - /** * The DataFlavor representing plain text with Unicode * encoding, where: *
@@ -241,15 +231,6 @@
     private static final PlatformLogger dtLog = PlatformLogger.getLogger("sun.awt.datatransfer.DataTransfer");
 
     static {
-        Class tCharArrayClass = null, tByteArrayClass = null;
-        try {
-            tCharArrayClass = Class.forName("[C");
-            tByteArrayClass = Class.forName("[B");
-        } catch (ClassNotFoundException cannotHappen) {
-        }
-        charArrayClass = tCharArrayClass;
-        byteArrayClass = tByteArrayClass;
-
         DataFlavor tPlainTextStringFlavor = null;
         try {
             tPlainTextStringFlavor = new DataFlavor
@@ -290,63 +271,8 @@
      * that in a headless environment, there may be no DataTransferer instance;
      * instead, null will be returned.
      */
-    public static DataTransferer getInstance() {
-        synchronized (DataTransferer.class) {
-            if (transferer == null) {
-                final String name = SunToolkit.getDataTransfererClassName();
-                if (name != null) {
-                    PrivilegedAction action = new PrivilegedAction()
-                    {
-                      public DataTransferer run() {
-                          Class cls = null;
-                          Method method = null;
-                          DataTransferer ret = null;
-
-                          try {
-                              cls = Class.forName(name);
-                          } catch (ClassNotFoundException e) {
-                              ClassLoader cl = ClassLoader.
-                                  getSystemClassLoader();
-                              if (cl != null) {
-                                  try {
-                                      cls = cl.loadClass(name);
-                                  } catch (ClassNotFoundException ee) {
-                                      ee.printStackTrace();
-                                      throw new AWTError("DataTransferer not found: " + name);
-                                  }
-                              }
-                          }
-                          if (cls != null) {
-                              try {
-                                  method = cls.getDeclaredMethod("getInstanceImpl");
-                                  method.setAccessible(true);
-                              } catch (NoSuchMethodException e) {
-                                  e.printStackTrace();
-                                  throw new AWTError("Cannot instantiate DataTransferer: " + name);
-                              } catch (SecurityException e) {
-                                  e.printStackTrace();
-                                  throw new AWTError("Access is denied for DataTransferer: " + name);
-                              }
-                          }
-                          if (method != null) {
-                              try {
-                                  ret = (DataTransferer) method.invoke(null);
-                              } catch (InvocationTargetException e) {
-                                  e.printStackTrace();
-                                  throw new AWTError("Cannot instantiate DataTransferer: " + name);
-                              } catch (IllegalAccessException e) {
-                                  e.printStackTrace();
-                                  throw new AWTError("Cannot access DataTransferer: " + name);
-                              }
-                          }
-                          return ret;
-                      }
-                    };
-                    transferer = AccessController.doPrivileged(action);
-                }
-            }
-        }
-        return transferer;
+    public static synchronized DataTransferer getInstance() {
+        return ((SunToolkit) Toolkit.getDefaultToolkit()).getDataTransferer();
     }
 
     /**
@@ -459,14 +385,14 @@
         if (flavor.isRepresentationClassReader() ||
             String.class.equals(rep_class) ||
             flavor.isRepresentationClassCharBuffer() ||
-            DataTransferer.charArrayClass.equals(rep_class))
+            char[].class.equals(rep_class))
         {
             return true;
         }
 
         if (!(flavor.isRepresentationClassInputStream() ||
               flavor.isRepresentationClassByteBuffer() ||
-              DataTransferer.byteArrayClass.equals(rep_class))) {
+              byte[].class.equals(rep_class))) {
             return false;
         }
 
@@ -490,8 +416,7 @@
 
         return (flavor.isRepresentationClassInputStream() ||
                 flavor.isRepresentationClassByteBuffer() ||
-                DataTransferer.byteArrayClass.
-                    equals(flavor.getRepresentationClass()));
+                byte[].class.equals(flavor.getRepresentationClass()));
     }
 
     /**
@@ -1243,7 +1168,7 @@
                 format);
 
         // Source data is a char array. Convert to a String and recur.
-        } else if (charArrayClass.equals(flavor.getRepresentationClass())) {
+        } else if (char[].class.equals(flavor.getRepresentationClass())) {
             if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
                 throw new IOException
                     ("cannot transfer non-text data as char array");
@@ -1274,7 +1199,7 @@
         // Source data is a byte array. For arbitrary flavors, simply return
         // the array. For text flavors, decode back to a String and recur to
         // reencode according to the requested format.
-        } else if (byteArrayClass.equals(flavor.getRepresentationClass())) {
+        } else if (byte[].class.equals(flavor.getRepresentationClass())) {
             byte[] bytes = (byte[])obj;
 
             if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
@@ -1651,7 +1576,7 @@
 
             // Target data is a char array. Recur to obtain String and convert to
             // char array.
-        } else if (charArrayClass.equals(flavor.getRepresentationClass())) {
+        } else if (char[].class.equals(flavor.getRepresentationClass())) {
             if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
                 throw new IOException
                           ("cannot transfer non-text data as char array");
@@ -1679,7 +1604,7 @@
             // the raw bytes. For text flavors, convert to a String to strip
             // terminators and search-and-replace EOLN, then reencode according to
             // the requested flavor.
-        } else if (byteArrayClass.equals(flavor.getRepresentationClass())) {
+        } else if (byte[].class.equals(flavor.getRepresentationClass())) {
             if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
                 theObject = translateBytesToString(
                     bytes, format, localeTransferable
@@ -1807,7 +1732,7 @@
 
             theObject = constructFlavoredObject(reader, flavor, Reader.class);
             // Target data is a byte array
-        } else if (byteArrayClass.equals(flavor.getRepresentationClass())) {
+        } else if (byte[].class.equals(flavor.getRepresentationClass())) {
             if(isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
                 theObject = translateBytesToString(inputStreamToByteArray(str), format, localeTransferable)
                         .getBytes(DataTransferer.getTextCharset(flavor));
@@ -2857,7 +2782,7 @@
                 HashMap decodedTextRepresentationsMap = new HashMap(4, 1.0f);
 
                 decodedTextRepresentationsMap.put
-                    (DataTransferer.charArrayClass, Integer.valueOf(0));
+                    (char[].class, Integer.valueOf(0));
                 decodedTextRepresentationsMap.put
                     (java.nio.CharBuffer.class, Integer.valueOf(1));
                 decodedTextRepresentationsMap.put
@@ -2873,7 +2798,7 @@
                 HashMap encodedTextRepresentationsMap = new HashMap(3, 1.0f);
 
                 encodedTextRepresentationsMap.put
-                    (DataTransferer.byteArrayClass, Integer.valueOf(0));
+                    (byte[].class, Integer.valueOf(0));
                 encodedTextRepresentationsMap.put
                     (java.nio.ByteBuffer.class, Integer.valueOf(1));
                 encodedTextRepresentationsMap.put
diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java
--- a/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java	Fri Jan 10 12:07:29 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java	Mon Jan 13 19:09:24 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,11 +77,9 @@
 
     private static XDataTransferer transferer;
 
-    static XDataTransferer getInstanceImpl() {
-        synchronized (XDataTransferer.class) {
-            if (transferer == null) {
-                transferer = new XDataTransferer();
-            }
+    static synchronized XDataTransferer getInstanceImpl() {
+        if (transferer == null) {
+            transferer = new XDataTransferer();
         }
         return transferer;
     }
@@ -411,7 +409,7 @@
         if (df.getRepresentationClass() != null &&
             (df.isRepresentationClassInputStream() ||
              df.isRepresentationClassByteBuffer() ||
-             byteArrayClass.equals(df.getRepresentationClass()))) {
+             byte[].class.equals(df.getRepresentationClass()))) {
             natives.add(mimeType);
         }
 
diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Jan 10 12:07:29 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Mon Jan 13 19:09:24 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,6 +47,7 @@
 import javax.swing.LookAndFeel;
 import javax.swing.UIDefaults;
 import sun.awt.*;
+import sun.awt.datatransfer.DataTransferer;
 import sun.font.FontConfigManager;
 import sun.java2d.SunGraphicsEnvironment;
 import sun.misc.PerformanceLogger;
@@ -300,8 +301,6 @@
         return awtAppClassName;
     }
 
-    static final String DATA_TRANSFERER_CLASS_NAME = "sun.awt.X11.XDataTransferer";
-
     public XToolkit() {
         super();
         if (PerformanceLogger.loggingEnabled()) {
@@ -323,7 +322,6 @@
 
             init();
             XWM.init();
-            SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
 
             PrivilegedAction action = new PrivilegedAction() {
                 public Thread run() {
@@ -1125,6 +1123,11 @@
         return false;
     }
 
+    @Override
+    public DataTransferer getDataTransferer() {
+        return XDataTransferer.getInstanceImpl();
+    }
+
     /**
      * Returns the supported cursor size
      */
diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java
--- a/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java	Fri Jan 10 12:07:29 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java	Mon Jan 13 19:09:24 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -159,13 +159,9 @@
 
     private static WDataTransferer transferer;
 
-    public static WDataTransferer getInstanceImpl() {
+    static synchronized WDataTransferer getInstanceImpl() {
         if (transferer == null) {
-            synchronized (WDataTransferer.class) {
-                if (transferer == null) {
-                    transferer = new WDataTransferer();
-                }
-            }
+            transferer = new WDataTransferer();
         }
         return transferer;
     }
diff -r 5bf4d2bd28f1 -r d68cbf54738f jdk/src/windows/classes/sun/awt/windows/WToolkit.java
--- a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Fri Jan 10 12:07:29 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Mon Jan 13 19:09:24 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
 import sun.awt.SunToolkit;
 import sun.awt.Win32GraphicsDevice;
 import sun.awt.Win32GraphicsEnvironment;
+import sun.awt.datatransfer.DataTransferer;
 import sun.java2d.d3d.D3DRenderQueue;
 import sun.java2d.opengl.OGLRenderQueue;
 
@@ -210,8 +211,6 @@
      */
     public native void embeddedEventLoopIdleProcessing();
 
-    public static final String DATA_TRANSFERER_CLASS_NAME = "sun.awt.windows.WDataTransferer";
-
     static class ToolkitDisposer implements sun.java2d.DisposerRecord {
         public void dispose() {
             WToolkit.postDispose();
@@ -255,8 +254,6 @@
             // swallow the exception
         }
 
-        SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
-
         // Enabled "live resizing" by default.  It remains controlled
         // by the native system though.
         setDynamicLayout(true);
@@ -514,6 +511,11 @@
         return true;
     }
 
+    @Override
+    public DataTransferer getDataTransferer() {
+        return WDataTransferer.getInstanceImpl();
+    }
+
     public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
       throws HeadlessException
     {