Our setMaximumSize, setMinimumSize, setPreferredSize do not clone the passed parameter, assigning it directly. If the user program reuses the passed object (for instance, to set the same property with different values for another component), the modifications both in Classpath and the user code cause the improper work.

Despite the current version produces less garbage, and very simple workaround is possible, Sun seems cloning the values (later changes on parameter have no effect).

This patch makes our behaviour consistent with Sun's.

2005-11-08  Audrius Meskauskas  <[EMAIL PROTECTED]>

* javax/swing/JComponent.java (setMaximumSize, setMinimumSize, setPreferredSize):
Clone the passed parameter.
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.75
diff -u -r1.75 JComponent.java
--- javax/swing/JComponent.java 2 Nov 2005 19:26:33 -0000       1.75
+++ javax/swing/JComponent.java 8 Nov 2005 10:18:42 -0000
@@ -2435,38 +2435,44 @@
   }
 
   /**
-   * Set the value of the [EMAIL PROTECTED] #maximumSize} property.
+   * Set the value of the [EMAIL PROTECTED] #maximumSize} property. The passed 
value is
+   * copied, the later direct changes on the argument have no effect on the
+   * property value.
    *
    * @param max The new value of the property
    */
   public void setMaximumSize(Dimension max)
   {
     Dimension oldMaximumSize = maximumSize;
-    maximumSize = max;
+    maximumSize = new Dimension(max);
     firePropertyChange("maximumSize", oldMaximumSize, maximumSize);
   }
 
   /**
-   * Set the value of the [EMAIL PROTECTED] #minimumSize} property.
+   * Set the value of the [EMAIL PROTECTED] #minimumSize} property. The passed 
value is
+   * copied, the later direct changes on the argument have no effect on the
+   * property value.
    *
    * @param min The new value of the property
    */
   public void setMinimumSize(Dimension min)
   {
     Dimension oldMinimumSize = minimumSize;
-    minimumSize = min;
+    minimumSize = new Dimension(min);
     firePropertyChange("minimumSize", oldMinimumSize, minimumSize);
   }
 
   /**
-   * Set the value of the [EMAIL PROTECTED] #preferredSize} property.
+   * Set the value of the [EMAIL PROTECTED] #preferredSize} property. The 
passed value is
+   * copied, the later direct changes on the argument have no effect on the
+   * property value.
    *
    * @param pref The new value of the property
    */
   public void setPreferredSize(Dimension pref)
   {
     Dimension oldPreferredSize = preferredSize;
-    preferredSize = pref;
+    preferredSize = new Dimension(pref);
     firePropertyChange("preferredSize", oldPreferredSize, preferredSize);
   }
 
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to