提交 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -39,7 +39,7 @@ import java.awt.datatransfer.UnsupportedFlavorException;
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 @@ public abstract class SunClipboard extends Clipboard
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 @@ public abstract class SunClipboard extends Clipboard
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 @@ public abstract class SunClipboard extends Clipboard
if (contextFlavorListeners.remove(listener) &&
--numberOfFlavorListeners == 0) {
unregisterClipboardViewerChecked();
currentDataFlavors = null;
currentFormats = null;
}
}
......@@ -420,17 +419,15 @@ public abstract class SunClipboard extends Clipboard
* @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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册