提交 d0ad57b0 编写于 作者: S serb

8043393: NullPointerException and no event received when clipboard data flavor changes

Reviewed-by: ant, azvegint
上级 964e5eb6
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -39,7 +39,7 @@ import java.awt.datatransfer.UnsupportedFlavorException; ...@@ -39,7 +39,7 @@ import java.awt.datatransfer.UnsupportedFlavorException;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
...@@ -75,12 +75,11 @@ public abstract class SunClipboard extends Clipboard ...@@ -75,12 +75,11 @@ public abstract class SunClipboard extends Clipboard
private volatile int numberOfFlavorListeners = 0; private volatile int numberOfFlavorListeners = 0;
/** /**
* A set of <code>DataFlavor</code>s that is available on * A set of {@code DataFlavor}s that is available on this clipboard. It is
* this clipboard. It is used for tracking changes * used for tracking changes of {@code DataFlavor}s available on this
* of <code>DataFlavor</code>s available on this clipboard. * clipboard. Can be {@code null}.
*/ */
private volatile Set currentDataFlavors; private volatile long[] currentFormats;
public SunClipboard(String name) { public SunClipboard(String name) {
super(name); super(name);
...@@ -367,11 +366,11 @@ public abstract class SunClipboard extends Clipboard ...@@ -367,11 +366,11 @@ public abstract class SunClipboard extends Clipboard
try { try {
openClipboard(null); openClipboard(null);
currentFormats = getClipboardFormats(); currentFormats = getClipboardFormats();
} catch (IllegalStateException exc) { } catch (final IllegalStateException ignored) {
} finally { } finally {
closeClipboard(); closeClipboard();
} }
currentDataFlavors = formatArrayAsDataFlavorSet(currentFormats); this.currentFormats = currentFormats;
registerClipboardViewerChecked(); registerClipboardViewerChecked();
} }
...@@ -391,7 +390,7 @@ public abstract class SunClipboard extends Clipboard ...@@ -391,7 +390,7 @@ public abstract class SunClipboard extends Clipboard
if (contextFlavorListeners.remove(listener) && if (contextFlavorListeners.remove(listener) &&
--numberOfFlavorListeners == 0) { --numberOfFlavorListeners == 0) {
unregisterClipboardViewerChecked(); unregisterClipboardViewerChecked();
currentDataFlavors = null; currentFormats = null;
} }
} }
...@@ -420,17 +419,15 @@ public abstract class SunClipboard extends Clipboard ...@@ -420,17 +419,15 @@ public abstract class SunClipboard extends Clipboard
* @param formats data formats that have just been retrieved from * @param formats data formats that have just been retrieved from
* this clipboard * this clipboard
*/ */
public void checkChange(long[] formats) { public final void checkChange(final long[] formats) {
Set prevDataFlavors = currentDataFlavors; if (Arrays.equals(formats, currentFormats)) {
currentDataFlavors = formatArrayAsDataFlavorSet(formats);
if ((prevDataFlavors != null) && (currentDataFlavors != null) &&
prevDataFlavors.equals(currentDataFlavors)) {
// we've been able to successfully get available on the clipboard // we've been able to successfully get available on the clipboard
// DataFlavors this and previous time and they are coincident; // DataFlavors this and previous time and they are coincident;
// don't notify // don't notify
return; return;
} }
currentFormats = formats;
class SunFlavorChangeNotifier implements Runnable { class SunFlavorChangeNotifier implements Runnable {
private final FlavorListener flavorListener; private final FlavorListener flavorListener;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册