From c3a9369016e7a2830412644b4cb6d052282f3267 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Wed, 9 Apr 2014 18:20:55 +0400 Subject: [PATCH] 8039752: Regression: Clipboard couldn't be used on linux Reviewed-by: anthony, serb, azvegint --- .../java/awt/datatransfer/Clipboard.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java b/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java index 880558aa71e..210c700941e 100644 --- a/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java +++ b/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java @@ -67,7 +67,7 @@ public class Clipboard { * * @since 1.5 */ - private final Set flavorListeners = new HashSet<>(); + private Set flavorListeners; /** * A set of DataFlavors that is available on @@ -85,7 +85,6 @@ public class Clipboard { */ public Clipboard(String name) { this.name = name; - currentDataFlavors = getAvailableDataFlavorSet(); } /** @@ -257,6 +256,12 @@ public class Clipboard { if (listener == null) { return; } + + if (flavorListeners == null) { + flavorListeners = new HashSet<>(); + currentDataFlavors = getAvailableDataFlavorSet(); + } + flavorListeners.add(listener); } @@ -278,7 +283,7 @@ public class Clipboard { * @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 @@ public class Clipboard { * @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 @@ public class Clipboard { * @since 1.5 */ private void fireFlavorsChanged() { + if (flavorListeners == null) { + return; + } + Set prevDataFlavors = currentDataFlavors; currentDataFlavors = getAvailableDataFlavorSet(); if (Objects.equals(prevDataFlavors, currentDataFlavors)) {