changeset 1620:a48c15bcf64f

6824600: OOM occurs when setLookAndFeel() is executed in Windows L&F(XP style) Reviewed-by: alexp
author rupashka
date Fri, 14 Aug 2009 13:18:10 +0400
parents 8e65977e4969
children fa334ff12794
files src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java src/share/classes/javax/swing/plaf/metal/MetalFontDesktopProperty.java src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java test/com/sun/java/swing/plaf/windows/Test6824600.java
diffstat 5 files changed, 148 insertions(+), 158 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java	Mon Aug 10 16:29:30 2009 +0400
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java	Fri Aug 14 13:18:10 2009 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -49,7 +49,7 @@
     /**
      * ReferenceQueue of unreferenced WeakPCLs.
      */
-    private static ReferenceQueue<DesktopProperty> queue;
+    private static final ReferenceQueue<DesktopProperty> queue = new ReferenceQueue<DesktopProperty>();
 
     /**
      * PropertyChangeListener attached to the Toolkit.
@@ -58,7 +58,7 @@
     /**
      * Key used to lookup value from desktop.
      */
-    private String key;
+    private final String key;
     /**
      * Value to return.
      */
@@ -66,17 +66,8 @@
     /**
      * Fallback value in case we get null from desktop.
      */
-    private Object fallback;
+    private final Object fallback;
 
-    /**
-     * Toolkit.
-     */
-    private Toolkit toolkit;
-
-
-    static {
-        queue = new ReferenceQueue<DesktopProperty>();
-    }
 
     /**
      * Cleans up any lingering state held by unrefeernced
@@ -138,13 +129,10 @@
      *
      * @param key Key used in looking up desktop value.
      * @param fallback Value used if desktop property is null.
-     * @param toolkit Toolkit used to fetch property from, can be null
-     *        in which default will be used.
      */
-    public DesktopProperty(String key, Object fallback, Toolkit toolkit) {
+    public DesktopProperty(String key, Object fallback) {
         this.key = key;
         this.fallback = fallback;
-        this.toolkit = toolkit;
         // The only sure fire way to clear our references is to create a
         // Thread and wait for a reference to be added to the queue.
         // Because it is so rare that you will actually change the look
@@ -175,13 +163,14 @@
      * Returns the value from the desktop.
      */
     protected Object getValueFromDesktop() {
-        if (this.toolkit == null) {
-            this.toolkit = Toolkit.getDefaultToolkit();
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
+
+        if (pcl == null) {
+            pcl = new WeakPCL(this, getKey(), UIManager.getLookAndFeel());
+            toolkit.addPropertyChangeListener(getKey(), pcl);
         }
-        Object value = toolkit.getDesktopProperty(getKey());
-        pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel());
-        toolkit.addPropertyChangeListener(getKey(), pcl);
-        return value;
+
+        return toolkit.getDesktopProperty(getKey());
     }
 
     /**
@@ -205,12 +194,7 @@
      * <code>createValue</code> will ask for the property again.
      */
     public void invalidate() {
-        if (pcl != null) {
-            toolkit.removePropertyChangeListener(getKey(), pcl);
-            toolkit = null;
-            pcl = null;
-            value = null;
-        }
+        value = null;
     }
 
     /**
@@ -271,13 +255,11 @@
      */
     private static class WeakPCL extends WeakReference<DesktopProperty>
                                implements PropertyChangeListener {
-        private Toolkit kit;
         private String key;
         private LookAndFeel laf;
 
-        WeakPCL(DesktopProperty target, Toolkit kit, String key, LookAndFeel laf) {
+        WeakPCL(DesktopProperty target, String key, LookAndFeel laf) {
             super(target, queue);
-            this.kit = kit;
             this.key = key;
             this.laf = laf;
         }
@@ -297,7 +279,7 @@
         }
 
         void dispose() {
-            kit.removePropertyChangeListener(key, this);
+            Toolkit.getDefaultToolkit().removePropertyChangeListener(key, this);
         }
     }
 }
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Mon Aug 10 16:29:30 2009 +0400
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Fri Aug 14 13:18:10 2009 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc.  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
@@ -104,7 +104,6 @@
         new StringUIClientPropertyKey(
             "WindowsLookAndFeel.generateHiResDisabledIcon");
 
-    private Toolkit toolkit;
     private boolean updatePending = false;
 
     private boolean useSystemFontSettings = true;
@@ -149,7 +148,6 @@
 
     public void initialize() {
         super.initialize();
-        toolkit = Toolkit.getDefaultToolkit();
 
         // Set the flag which determines which version of Windows should
         // be rendered. This flag only need to be set once.
@@ -470,80 +468,61 @@
 
         Object ControlBackgroundColor = new DesktopProperty(
                                                        "win.3d.backgroundColor",
-                                                        table.get("control"),
-                                                       toolkit);
+                                                        table.get("control"));
         Object ControlLightColor      = new DesktopProperty(
                                                        "win.3d.lightColor",
-                                                        table.get("controlHighlight"),
-                                                       toolkit);
+                                                        table.get("controlHighlight"));
         Object ControlHighlightColor  = new DesktopProperty(
                                                        "win.3d.highlightColor",
-                                                        table.get("controlLtHighlight"),
-                                                       toolkit);
+                                                        table.get("controlLtHighlight"));
         Object ControlShadowColor     = new DesktopProperty(
                                                        "win.3d.shadowColor",
-                                                        table.get("controlShadow"),
-                                                       toolkit);
+                                                        table.get("controlShadow"));
         Object ControlDarkShadowColor = new DesktopProperty(
                                                        "win.3d.darkShadowColor",
-                                                        table.get("controlDkShadow"),
-                                                       toolkit);
+                                                        table.get("controlDkShadow"));
         Object ControlTextColor       = new DesktopProperty(
                                                        "win.button.textColor",
-                                                        table.get("controlText"),
-                                                       toolkit);
+                                                        table.get("controlText"));
         Object MenuBackgroundColor    = new DesktopProperty(
                                                        "win.menu.backgroundColor",
-                                                        table.get("menu"),
-                                                       toolkit);
+                                                        table.get("menu"));
         Object MenuBarBackgroundColor = new DesktopProperty(
                                                        "win.menubar.backgroundColor",
-                                                        table.get("menu"),
-                                                       toolkit);
+                                                        table.get("menu"));
         Object MenuTextColor          = new DesktopProperty(
                                                        "win.menu.textColor",
-                                                        table.get("menuText"),
-                                                       toolkit);
+                                                        table.get("menuText"));
         Object SelectionBackgroundColor = new DesktopProperty(
                                                        "win.item.highlightColor",
-                                                        table.get("textHighlight"),
-                                                       toolkit);
+                                                        table.get("textHighlight"));
         Object SelectionTextColor     = new DesktopProperty(
                                                        "win.item.highlightTextColor",
-                                                        table.get("textHighlightText"),
-                                                       toolkit);
+                                                        table.get("textHighlightText"));
         Object WindowBackgroundColor  = new DesktopProperty(
                                                        "win.frame.backgroundColor",
-                                                        table.get("window"),
-                                                       toolkit);
+                                                        table.get("window"));
         Object WindowTextColor        = new DesktopProperty(
                                                        "win.frame.textColor",
-                                                        table.get("windowText"),
-                                                       toolkit);
+                                                        table.get("windowText"));
         Object WindowBorderWidth      = new DesktopProperty(
                                                        "win.frame.sizingBorderWidth",
-                                                       Integer.valueOf(1),
-                                                       toolkit);
+                                                       Integer.valueOf(1));
         Object TitlePaneHeight        = new DesktopProperty(
                                                        "win.frame.captionHeight",
-                                                       Integer.valueOf(18),
-                                                       toolkit);
+                                                       Integer.valueOf(18));
         Object TitleButtonWidth       = new DesktopProperty(
                                                        "win.frame.captionButtonWidth",
-                                                       Integer.valueOf(16),
-                                                       toolkit);
+                                                       Integer.valueOf(16));
         Object TitleButtonHeight      = new DesktopProperty(
                                                        "win.frame.captionButtonHeight",
-                                                       Integer.valueOf(16),
-                                                       toolkit);
+                                                       Integer.valueOf(16));
         Object InactiveTextColor      = new DesktopProperty(
                                                        "win.text.grayedTextColor",
-                                                        table.get("textInactiveText"),
-                                                       toolkit);
+                                                        table.get("textInactiveText"));
         Object ScrollbarBackgroundColor = new DesktopProperty(
                                                        "win.scrollbar.backgroundColor",
-                                                        table.get("scrollbar"),
-                                                       toolkit);
+                                                        table.get("scrollbar"));
 
         Object TextBackground         = new XPColorValue(Part.EP_EDIT, null, Prop.FILLCOLOR,
                                                          WindowBackgroundColor);
@@ -566,32 +545,22 @@
         Object ToolTipFont = sansSerifPlain12;
         Object IconFont = ControlFont;
 
-        Object scrollBarWidth = new DesktopProperty("win.scrollbar.width",
-                                                    Integer.valueOf(16), toolkit);
+        Object scrollBarWidth = new DesktopProperty("win.scrollbar.width", Integer.valueOf(16));
 
-        Object menuBarHeight = new DesktopProperty("win.menu.height",
-                                                   null, toolkit);
+        Object menuBarHeight = new DesktopProperty("win.menu.height", null);
 
-        Object hotTrackingOn = new DesktopProperty("win.item.hotTrackingOn",
-                                                   true, toolkit);
+        Object hotTrackingOn = new DesktopProperty("win.item.hotTrackingOn", true);
 
-        Object showMnemonics = new DesktopProperty("win.menu.keyboardCuesOn",
-                                                     Boolean.TRUE, toolkit);
+        Object showMnemonics = new DesktopProperty("win.menu.keyboardCuesOn", Boolean.TRUE);
 
         if (useSystemFontSettings) {
-            MenuFont = getDesktopFontValue("win.menu.font", MenuFont, toolkit);
-            FixedControlFont = getDesktopFontValue("win.ansiFixed.font",
-                                                   FixedControlFont, toolkit);
-            ControlFont = getDesktopFontValue("win.defaultGUI.font",
-                                              ControlFont, toolkit);
-            MessageFont = getDesktopFontValue("win.messagebox.font",
-                                              MessageFont, toolkit);
-            WindowFont = getDesktopFontValue("win.frame.captionFont",
-                                             WindowFont, toolkit);
-            IconFont    = getDesktopFontValue("win.icon.font",
-                                              IconFont, toolkit);
-            ToolTipFont = getDesktopFontValue("win.tooltip.font", ToolTipFont,
-                                              toolkit);
+            MenuFont = getDesktopFontValue("win.menu.font", MenuFont);
+            FixedControlFont = getDesktopFontValue("win.ansiFixed.font", FixedControlFont);
+            ControlFont = getDesktopFontValue("win.defaultGUI.font", ControlFont);
+            MessageFont = getDesktopFontValue("win.messagebox.font", MessageFont);
+            WindowFont = getDesktopFontValue("win.frame.captionFont", WindowFont);
+            IconFont    = getDesktopFontValue("win.icon.font", IconFont);
+            ToolTipFont = getDesktopFontValue("win.tooltip.font", ToolTipFont);
 
             /* Put the desktop AA settings in the defaults.
              * JComponent.setUI() retrieves this and makes it available
@@ -605,26 +574,14 @@
                 new FontDesktopProperty(SunToolkit.DESKTOPFONTHINTS);
         }
         if (useSystemFontSizeSettings) {
-            MenuFont = new WindowsFontSizeProperty("win.menu.font.height",
-                                  toolkit, Font.DIALOG, Font.PLAIN, 12);
-            FixedControlFont = new WindowsFontSizeProperty(
-                       "win.ansiFixed.font.height", toolkit, Font.MONOSPACED,
+            MenuFont = new WindowsFontSizeProperty("win.menu.font.height", Font.DIALOG, Font.PLAIN, 12);
+            FixedControlFont = new WindowsFontSizeProperty("win.ansiFixed.font.height", Font.MONOSPACED,
                        Font.PLAIN, 12);
-            ControlFont = new WindowsFontSizeProperty(
-                        "win.defaultGUI.font.height", toolkit, Font.DIALOG,
-                        Font.PLAIN, 12);
-            MessageFont = new WindowsFontSizeProperty(
-                              "win.messagebox.font.height",
-                              toolkit, Font.DIALOG, Font.PLAIN, 12);
-            WindowFont = new WindowsFontSizeProperty(
-                             "win.frame.captionFont.height", toolkit,
-                             Font.DIALOG, Font.BOLD, 12);
-            ToolTipFont = new WindowsFontSizeProperty(
-                              "win.tooltip.font.height", toolkit, Font.SANS_SERIF,
-                              Font.PLAIN, 12);
-            IconFont    = new WindowsFontSizeProperty(
-                              "win.icon.font.height", toolkit, Font.DIALOG,
-                              Font.PLAIN, 12);
+            ControlFont = new WindowsFontSizeProperty("win.defaultGUI.font.height", Font.DIALOG, Font.PLAIN, 12);
+            MessageFont = new WindowsFontSizeProperty("win.messagebox.font.height", Font.DIALOG, Font.PLAIN, 12);
+            WindowFont = new WindowsFontSizeProperty("win.frame.captionFont.height", Font.DIALOG, Font.BOLD, 12);
+            ToolTipFont = new WindowsFontSizeProperty("win.tooltip.font.height", Font.SANS_SERIF, Font.PLAIN, 12);
+            IconFont    = new WindowsFontSizeProperty("win.icon.font.height", Font.DIALOG, Font.PLAIN, 12);
         }
 
 
@@ -752,8 +709,7 @@
             // DeskTop.
             "Desktop.background", new DesktopProperty(
                                                  "win.desktop.backgroundColor",
-                                                  table.get("desktop"),
-                                                 toolkit),
+                                                  table.get("desktop")),
             "Desktop.ancestorInputMap",
                new UIDefaults.LazyInputMap(new Object[] {
                    "ctrl F5", "restore",
@@ -819,7 +775,7 @@
             "FileChooser.filesOfTypeLabelMnemonic", Integer.valueOf(KeyEvent.VK_T),
             "FileChooser.usesSingleFilePane", Boolean.TRUE,
             "FileChooser.noPlacesBar", new DesktopProperty("win.comdlg.noPlacesBar",
-                                                           Boolean.FALSE, toolkit),
+                                                           Boolean.FALSE),
             "FileChooser.ancestorInputMap",
                new UIDefaults.LazyInputMap(new Object[] {
                      "ESCAPE", "cancelSelection",
@@ -861,36 +817,28 @@
             "InternalFrame.resizeIconShadow", ControlShadowColor,
             "InternalFrame.activeBorderColor", new DesktopProperty(
                                                        "win.frame.activeBorderColor",
-                                                       table.get("windowBorder"),
-                                                       toolkit),
+                                                       table.get("windowBorder")),
             "InternalFrame.inactiveBorderColor", new DesktopProperty(
                                                        "win.frame.inactiveBorderColor",
-                                                       table.get("windowBorder"),
-                                                       toolkit),
+                                                       table.get("windowBorder")),
             "InternalFrame.activeTitleBackground", new DesktopProperty(
                                                         "win.frame.activeCaptionColor",
-                                                         table.get("activeCaption"),
-                                                        toolkit),
+                                                         table.get("activeCaption")),
             "InternalFrame.activeTitleGradient", new DesktopProperty(
                                                         "win.frame.activeCaptionGradientColor",
-                                                         table.get("activeCaption"),
-                                                        toolkit),
+                                                         table.get("activeCaption")),
             "InternalFrame.activeTitleForeground", new DesktopProperty(
                                                         "win.frame.captionTextColor",
-                                                         table.get("activeCaptionText"),
-                                                        toolkit),
+                                                         table.get("activeCaptionText")),
             "InternalFrame.inactiveTitleBackground", new DesktopProperty(
                                                         "win.frame.inactiveCaptionColor",
-                                                         table.get("inactiveCaption"),
-                                                        toolkit),
+                                                         table.get("inactiveCaption")),
             "InternalFrame.inactiveTitleGradient", new DesktopProperty(
                                                         "win.frame.inactiveCaptionGradientColor",
-                                                         table.get("inactiveCaption"),
-                                                        toolkit),
+                                                         table.get("inactiveCaption")),
             "InternalFrame.inactiveTitleForeground", new DesktopProperty(
                                                         "win.frame.inactiveCaptionTextColor",
-                                                         table.get("inactiveCaptionText"),
-                                                        toolkit),
+                                                         table.get("inactiveCaptionText")),
 
             "InternalFrame.maximizeIcon",
                 WindowsIconFactory.createFrameMaximizeIcon(),
@@ -1529,12 +1477,8 @@
 
             // *** ToolTip
             "ToolTip.font", ToolTipFont,
-            "ToolTip.background", new DesktopProperty(
-                                           "win.tooltip.backgroundColor",
-                                            table.get("info"), toolkit),
-            "ToolTip.foreground", new DesktopProperty(
-                                           "win.tooltip.textColor",
-                                            table.get("infoText"), toolkit),
+            "ToolTip.background", new DesktopProperty("win.tooltip.backgroundColor", table.get("info")),
+            "ToolTip.foreground", new DesktopProperty("win.tooltip.textColor", table.get("infoText")),
 
         // *** ToolTipManager
             "ToolTipManager.enableToolTipMode", "activeApplication",
@@ -1798,10 +1742,9 @@
      * represented in the current encoding this will return null and
      * turn off the use of system fonts.
      */
-    private Object getDesktopFontValue(String fontName, Object backup,
-                                       Toolkit kit) {
+    private Object getDesktopFontValue(String fontName, Object backup) {
         if (useSystemFontSettings) {
-            return new WindowsFontProperty(fontName, backup, kit);
+            return new WindowsFontProperty(fontName, backup);
         }
         return null;
     }
@@ -1989,7 +1932,6 @@
 
     public void uninitialize() {
         super.uninitialize();
-        toolkit = null;
 
         if (WindowsPopupMenuUI.mnemonicListener != null) {
             MenuSelectionManager.defaultManager().
@@ -2309,8 +2251,8 @@
      * is returned, it is mapped to 'Microsoft Sans Serif'.
      */
     private static class WindowsFontProperty extends DesktopProperty {
-        WindowsFontProperty(String key, Object backup, Toolkit kit) {
-            super(key, backup, kit);
+        WindowsFontProperty(String key, Object backup) {
+            super(key, backup);
         }
 
         public void invalidate(LookAndFeel laf) {
@@ -2372,9 +2314,9 @@
         private int fontSize;
         private int fontStyle;
 
-        WindowsFontSizeProperty(String key, Toolkit toolkit, String fontName,
+        WindowsFontSizeProperty(String key, String fontName,
                                 int fontStyle, int fontSize) {
-            super(key, null, toolkit);
+            super(key, null);
             this.fontName = fontName;
             this.fontSize = fontSize;
             this.fontStyle = fontStyle;
@@ -2508,7 +2450,7 @@
 
     private class TriggerDesktopProperty extends DesktopProperty {
         TriggerDesktopProperty(String key) {
-            super(key, null, toolkit);
+            super(key, null);
             // This call adds a property change listener for the property,
             // which triggers a call to updateUI(). The value returned
             // is not interesting here.
--- a/src/share/classes/javax/swing/plaf/metal/MetalFontDesktopProperty.java	Mon Aug 10 16:29:30 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/metal/MetalFontDesktopProperty.java	Fri Aug 14 13:18:10 2009 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -25,8 +25,6 @@
 package javax.swing.plaf.metal;
 
 import java.awt.*;
-import java.beans.*;
-import javax.swing.*;
 
 /**
  * DesktopProperty that only uses font height in configuring font. This
@@ -60,7 +58,7 @@
      * @param type MetalTheme font type.
      */
     MetalFontDesktopProperty(int type) {
-        this(propertyMapping[type], Toolkit.getDefaultToolkit(), type);
+        this(propertyMapping[type], type);
     }
 
     /**
@@ -72,8 +70,8 @@
      * @param type Type of font being used, corresponds to MetalTheme font
      *        type.
      */
-    MetalFontDesktopProperty(String key, Toolkit kit, int type) {
-        super(key, null, kit);
+    MetalFontDesktopProperty(String key, int type) {
+        super(key, null);
         this.type = type;
     }
 
--- a/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java	Mon Aug 10 16:29:30 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java	Fri Aug 14 13:18:10 2009 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1998-2009 Sun Microsystems, Inc.  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
@@ -1541,10 +1541,8 @@
         table.putDefaults(defaults);
 
         if (isWindows() && useSystemFonts() && theme.isSystemTheme()) {
-            Toolkit kit = Toolkit.getDefaultToolkit();
             Object messageFont = new MetalFontDesktopProperty(
-                              "win.messagebox.font.height", kit, MetalTheme.
-                              CONTROL_TEXT_FONT);
+                "win.messagebox.font.height", MetalTheme.CONTROL_TEXT_FONT);
 
             defaults = new Object[] {
                 "OptionPane.messageFont", messageFont,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/java/swing/plaf/windows/Test6824600.java	Fri Aug 14 13:18:10 2009 +0400
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 6824600
+   @summary OOM occurs when setLookAndFeel() is executed in Windows L&F(XP style)
+   @author Pavel Porvatov
+   @run main Test6824600
+*/
+
+import com.sun.java.swing.plaf.windows.DesktopProperty;
+
+import java.awt.*;
+
+public class Test6824600 {
+    public static void main(String[] args) throws Exception {
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
+
+        HackedDesktopProperty desktopProperty = new HackedDesktopProperty("Button.background", null);
+
+        // Register listener in toolkit
+        desktopProperty.getValueFromDesktop();
+
+        int length = toolkit.getPropertyChangeListeners().length;
+
+        // Make several invocations
+        desktopProperty.getValueFromDesktop();
+        desktopProperty.getValueFromDesktop();
+
+        desktopProperty.invalidate();
+
+        desktopProperty.getValueFromDesktop();
+        desktopProperty.getValueFromDesktop();
+
+        if (length != toolkit.getPropertyChangeListeners().length) {
+            throw new RuntimeException("New listeners were added into Toolkit");
+        }
+    }
+
+    public static class HackedDesktopProperty extends DesktopProperty {
+        public HackedDesktopProperty(String key, Object fallback) {
+            super(key, fallback);
+        }
+
+        // Publish the method
+        public Object getValueFromDesktop() {
+            return super.getValueFromDesktop();
+        }
+    }
+}