8039752: Regression: Clipboard couldn't be used on linux
authorpchelko
Wed, 09 Apr 2014 18:20:55 +0400
changeset 24172 814fb69fa9a5
parent 24171 9a263c3c482b
child 24173 176b551268a3
8039752: Regression: Clipboard couldn't be used on linux Reviewed-by: anthony, serb, azvegint
jdk/src/share/classes/java/awt/datatransfer/Clipboard.java
--- a/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java	Wed Apr 09 17:30:42 2014 +0400
+++ b/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java	Wed Apr 09 18:20:55 2014 +0400
@@ -67,7 +67,7 @@
      *
      * @since 1.5
      */
-    private final Set<FlavorListener> flavorListeners = new HashSet<>();
+    private Set<FlavorListener> flavorListeners;
 
     /**
      * A set of <code>DataFlavor</code>s that is available on
@@ -85,7 +85,6 @@
      */
     public Clipboard(String name) {
         this.name = name;
-        currentDataFlavors = getAvailableDataFlavorSet();
     }
 
     /**
@@ -257,6 +256,12 @@
         if (listener == null) {
             return;
         }
+
+        if (flavorListeners == null) {
+            flavorListeners = new HashSet<>();
+            currentDataFlavors = getAvailableDataFlavorSet();
+        }
+
         flavorListeners.add(listener);
     }
 
@@ -278,7 +283,7 @@
      * @since 1.5
      */
     public synchronized void removeFlavorListener(FlavorListener listener) {
-        if (listener == null) {
+        if (listener == null || flavorListeners == null) {
             return;
         }
         flavorListeners.remove(listener);
@@ -297,7 +302,8 @@
      * @since 1.5
      */
     public synchronized FlavorListener[] getFlavorListeners() {
-        return flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
+        return flavorListeners == null ? new FlavorListener[0] :
+            flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
     }
 
     /**
@@ -308,6 +314,10 @@
      * @since 1.5
      */
     private void fireFlavorsChanged() {
+        if (flavorListeners == null) {
+            return;
+        }
+
         Set<DataFlavor> prevDataFlavors = currentDataFlavors;
         currentDataFlavors = getAvailableDataFlavorSet();
         if (Objects.equals(prevDataFlavors, currentDataFlavors)) {