8043393: NullPointerException and no event received when clipboard data flavor changes
Reviewed-by: ant, azvegint
--- a/jdk/src/java.desktop/share/classes/sun/awt/datatransfer/SunClipboard.java Mon Feb 23 10:47:32 2015 -0800
+++ b/jdk/src/java.desktop/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
@@ -40,7 +40,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.Objects;
+import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;
@@ -74,12 +74,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<DataFlavor> currentDataFlavors;
-
+ private volatile long[] currentFormats;
public SunClipboard(String name) {
super(name);
@@ -362,11 +361,11 @@
try {
openClipboard(null);
currentFormats = getClipboardFormats();
- } catch (IllegalStateException exc) {
+ } catch (final IllegalStateException ignored) {
} finally {
closeClipboard();
}
- currentDataFlavors = formatArrayAsDataFlavorSet(currentFormats);
+ this.currentFormats = currentFormats;
registerClipboardViewerChecked();
}
@@ -383,7 +382,7 @@
}
if (flavorListeners.remove(listener) && --numberOfFlavorListeners == 0) {
unregisterClipboardViewerChecked();
- currentDataFlavors = null;
+ currentFormats = null;
}
}
@@ -416,18 +415,16 @@
* @param formats data formats that have just been retrieved from
* this clipboard
*/
- public void checkChange(long[] formats) {
- Set<DataFlavor> prevDataFlavors = currentDataFlavors;
- currentDataFlavors = formatArrayAsDataFlavorSet(formats);
-
- if (Objects.equals(prevDataFlavors, 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;
- for (AppContext appContext : AppContext.getAppContexts()) {
+ for (final AppContext appContext : AppContext.getAppContexts()) {
if (appContext == null || appContext.isDisposed()) {
continue;
}