changeset 10717:19dd7826703c

8043393: NullPointerException and no event received when clipboard data flavor changes Reviewed-by: ant, azvegint
author serb
date Wed, 25 Feb 2015 14:01:27 +0300
parents 49d721334df5
children 5c230a775f01
files src/share/classes/sun/awt/datatransfer/SunClipboard.java
diffstat 1 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/awt/datatransfer/SunClipboard.java	Mon Feb 02 18:21:24 2015 +0300
+++ b/src/share/classes/sun/awt/datatransfer/SunClipboard.java	Wed Feb 25 14:01:27 2015 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -39,7 +39,7 @@
 
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.HashSet;
@@ -75,12 +75,11 @@
     private volatile int numberOfFlavorListeners = 0;
 
     /**
-     * A set of <code>DataFlavor</code>s that is available on
-     * this clipboard. It is used for tracking changes
-     * of <code>DataFlavor</code>s available on this clipboard.
+     * A set of {@code DataFlavor}s that is available on this clipboard. It is
+     * used for tracking changes of {@code DataFlavor}s available on this
+     * clipboard. Can be {@code null}.
      */
-    private volatile Set currentDataFlavors;
-
+    private volatile long[] currentFormats;
 
     public SunClipboard(String name) {
         super(name);
@@ -367,11 +366,11 @@
             try {
                 openClipboard(null);
                 currentFormats = getClipboardFormats();
-            } catch (IllegalStateException exc) {
+            } catch (final IllegalStateException ignored) {
             } finally {
                 closeClipboard();
             }
-            currentDataFlavors = formatArrayAsDataFlavorSet(currentFormats);
+            this.currentFormats = currentFormats;
 
             registerClipboardViewerChecked();
         }
@@ -391,7 +390,7 @@
         if (contextFlavorListeners.remove(listener) &&
                 --numberOfFlavorListeners == 0) {
             unregisterClipboardViewerChecked();
-            currentDataFlavors = null;
+            currentFormats = null;
         }
     }
 
@@ -420,17 +419,15 @@
      * @param formats data formats that have just been retrieved from
      *        this clipboard
      */
-    public void checkChange(long[] formats) {
-        Set prevDataFlavors = currentDataFlavors;
-        currentDataFlavors = formatArrayAsDataFlavorSet(formats);
-
-        if ((prevDataFlavors != null) && (currentDataFlavors != null) &&
-                prevDataFlavors.equals(currentDataFlavors)) {
+    public final void checkChange(final long[] formats) {
+        if (Arrays.equals(formats, currentFormats)) {
             // we've been able to successfully get available on the clipboard
             // DataFlavors this and previous time and they are coincident;
             // don't notify
             return;
         }
+        currentFormats = formats;
+
 
         class SunFlavorChangeNotifier implements Runnable {
             private final FlavorListener flavorListener;