harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r582382 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/ test/api/java/common/java/awt/
Date Fri, 05 Oct 2007 20:45:40 GMT
Author: ayza
Date: Fri Oct  5 13:45:39 2007
New Revision: 582382

URL: http://svn.apache.org/viewvc?rev=582382&view=rev
Log:
Fix for dead loop issues described in HARMONY-4887 and HARMONY-4803 was committed

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Button.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Checkbox.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Choice.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Component.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Container.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Label.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/CheckboxTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ChoiceTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ComponentRTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/LabelTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextComponentTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextFieldTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/Tools.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Button.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Button.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Button.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Button.java
Fri Oct  5 13:45:39 2007
@@ -166,11 +166,16 @@
     public void setLabel(String label) {
         toolkit.lockAWT();
         try {
-            this.label = label;
-            if (isDisplayable()) {
-                invalidate();
-                if (isShowing()) {
-                    repaint();
+            if (!(this.label == label ||
+                    (label != null && label.equals(this.label)))) {
+                // set new label only if it differs from the old one
+                // to avoid dead loop in repaint()
+                this.label = label;
+                if (isDisplayable()) {
+                    invalidate();
+                    if (isShowing()) {
+                        repaint();
+                    }
                 }
             }
         } finally {
@@ -296,8 +301,10 @@
 
     @Override
     void setEnabledImpl(boolean value) {
-        super.setEnabledImpl(value);
-        repaint();
+        if (isEnabled() != value) { // to avoid dead loop in repaint()
+            super.setEnabledImpl(value);
+            repaint();
+        }
     }
 
     void generateEvent(long timestamp, int modifiers) {

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Checkbox.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Checkbox.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Checkbox.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Checkbox.java
Fri Oct  5 13:45:39 2007
@@ -351,8 +351,10 @@
     }
 
     void setChecked(boolean checked) {
-        this.checked = checked;
-        repaint();
+        if (checked != this.checked) { // avoid dead loop in repaint()
+            this.checked = checked;
+            repaint();
+        }
     }
 
     @SuppressWarnings("unchecked")
@@ -437,8 +439,10 @@
 
     @Override
     void setEnabledImpl(boolean value) {
-        super.setEnabledImpl(value);
-        repaint();
+        if (value != isEnabled()) { // avoid dead loop in repaint()
+            super.setEnabledImpl(value);
+            repaint();
+        }    
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Choice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Choice.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Choice.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Choice.java
Fri Oct  5 13:45:39 2007
@@ -479,12 +479,15 @@
     public void select(int pos) {
         toolkit.lockAWT();
         try {
-            if (pos >= items.size() || pos < 0) {
-                // awt.106=specified position is greater than the number of items
-                throw new IllegalArgumentException(Messages.getString("awt.106")); //$NON-NLS-1$
+            if (selectedIndex != pos) { // to avoid dead loop in repaint()
+                if (pos >= items.size() || pos < 0) {
+                    // awt.106=specified position is greater than the number of items
+                    throw new IllegalArgumentException(
+                            Messages.getString("awt.106")); //$NON-NLS-1$
+                }
+                selectedIndex = pos;
+                repaint();
             }
-            selectedIndex = pos;
-            repaint();
         } finally {
             toolkit.unlockAWT();
         }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Component.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Component.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Component.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Component.java
Fri Oct  5 13:45:39 2007
@@ -2985,10 +2985,13 @@
     }
 
     void setFontImpl(Font f) {
-        font = f;
-        invalidate();
-        if (isShowing()) {
-            repaint();
+        if (!(f == font ||
+             (f != null && f.equals(font)))) {// to avoid dead loop in repaint()
+            font = f;
+            invalidate();
+            if (isShowing()) {
+                repaint();
+            }
         }
     }
 
@@ -3009,6 +3012,7 @@
 
     public void setForeground(Color c) {
         Color oldFgColor;
+
         toolkit.lockAWT();
         try {
             oldFgColor = foreColor;
@@ -3016,21 +3020,34 @@
         } finally {
             toolkit.unlockAWT();
         }
-        firePropertyChange("foreground", oldFgColor, foreColor); //$NON-NLS-1$
-        repaint();
+        
+        // Update only if new color differs from the old one.
+        // It is needed to avoid dead loops in repaint().
+        if (!(oldFgColor == c ||
+              (c != null && c.equals(oldFgColor)))) {
+            firePropertyChange("foreground", oldFgColor, c); //$NON-NLS-1$
+            repaint();
+        }
     }
 
     public void setBackground(Color c) {
-        Color oldBkColor;
+        Color oldBgColor;
+        
         toolkit.lockAWT();
         try {
-            oldBkColor = backColor;
+            oldBgColor = backColor;
             backColor = c;
         } finally {
             toolkit.unlockAWT();
         }
-        firePropertyChange("background", oldBkColor, backColor); //$NON-NLS-1$
-        repaint();
+        
+        // update only if new color differs from the old one
+        // to avoid dead loop in repaint()
+        if (!(c == oldBgColor || 
+                 (c != null && c.equals(oldBgColor)))) {
+            firePropertyChange("background", oldBgColor, c); //$NON-NLS-1$
+            repaint();
+        }
     }
 
     public void setIgnoreRepaint(boolean value) {

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Container.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Container.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Container.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Container.java
Fri Oct  5 13:45:39 2007
@@ -1321,8 +1321,8 @@
      * Determine if comp contains point pos. Comp must be showing and top-most
      * component in Z-order.
      * 
-     * @param x
-     * @param y
+     * @param comp component to look for
+     * @param pos point to look component at
      * 
      * @return
      */

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Label.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Label.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Label.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Label.java Fri
Oct  5 13:45:39 2007
@@ -250,8 +250,10 @@
 
     @Override
     void setEnabledImpl(boolean value) {
-        super.setEnabledImpl(value);
-        repaint();
+        if (value != isEnabled()) { // to avoid dead loop in repaint()
+            super.setEnabledImpl(value);
+            repaint();
+        }
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java
Fri Oct  5 13:45:39 2007
@@ -774,8 +774,10 @@
     public void setEditable(boolean b) {
         toolkit.lockAWT();
         try {
-            editable = b;
-            repaint(); // background color changes
+            if (editable != b) {  // to avoid dead loop in repaint()
+                editable = b;
+                repaint(); // background color changes
+            }
         } finally {
             toolkit.unlockAWT();
         }
@@ -1094,9 +1096,11 @@
 
     @Override
     void setEnabledImpl(boolean value) {
-        super.setEnabledImpl(value);
-        if (isShowing()) {
-            repaint();
+        if (value != isEnabled()) { // to avoid dead loop in repaint()
+            super.setEnabledImpl(value);
+            if (isShowing()) {
+                repaint();
+            }
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
Fri Oct  5 13:45:39 2007
@@ -28,7 +28,7 @@
 import junit.framework.TestCase;
 
 public class ButtonRTest extends TestCase {
-
+  
     public void testShowAndPack() {
         Frame frm = new Frame("Test");
         Button btnClose = new Button("MyClose");
@@ -89,6 +89,19 @@
         testHarmony2305();
     }
 
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Button b = new Button() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setEnabled(true);
+                setLabel("button1");
+            }
+        };
+        
+        Tools.checkDeadLoop(b, count);
+    }
+    
     static class AL implements ActionListener {
         ActionEvent e;
 
@@ -96,4 +109,5 @@
             this.e = e;
         }
     }
+    
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/CheckboxTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/CheckboxTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/CheckboxTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/CheckboxTest.java
Fri Oct  5 13:45:39 2007
@@ -208,4 +208,18 @@
         checkbox.removeItemListener(listener);
         assertEquals(0, checkbox.getListeners(cls).length);
     }
+    
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new Checkbox() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setState(true);
+                setEnabled(true);
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
+
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ChoiceTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ChoiceTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ChoiceTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ChoiceTest.java
Fri Oct  5 13:45:39 2007
@@ -365,4 +365,18 @@
         assertTrue(eventProcessed);
     }
 
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new Choice() {
+            public void paint(Graphics g) {
+                count[0]++;
+                if (getItemCount() == 0) {
+                    add("item");      
+                }
+                select(0);
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ComponentRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ComponentRTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ComponentRTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ComponentRTest.java
Fri Oct  5 13:45:39 2007
@@ -78,6 +78,20 @@
         // Regression test for HARMONY-2456
         new Button().transferFocusUpCycle();
     }
+    
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new Panel() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setBackground(new Color(255, 255, 255));
+                setForeground(Color.BLACK);
+                setFont(new Font("Serif", Font.PLAIN, 10));
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
 
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ComponentRTest.class);

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/LabelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/LabelTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/LabelTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/LabelTest.java
Fri Oct  5 13:45:39 2007
@@ -112,4 +112,16 @@
         assertEquals(text, label.getText());
     }
 
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new Label() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setEnabled(true);
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
+    
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextComponentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextComponentTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextComponentTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextComponentTest.java
Fri Oct  5 13:45:39 2007
@@ -409,4 +409,16 @@
         assertTrue("text event processed", eventProcessed);
     }
 
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new TextArea() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setEditable(true);
+                setEnabled(true);
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextFieldTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextFieldTest.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextFieldTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/TextFieldTest.java
Fri Oct  5 13:45:39 2007
@@ -431,5 +431,17 @@
                                         null, 0, 0));
         assertTrue(eventProcessed);
     }
+    
+    public void testDeadLoop4887() {
+        final int count[] = new int[1];
+        Component c = new TextField() {
+            public void paint(Graphics g) {
+                count[0]++;
+                setEchoChar(' ');
+            }
+        };
+        
+        Tools.checkDeadLoop(c, count);
+    }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/Tools.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/Tools.java?rev=582382&r1=582381&r2=582382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/Tools.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/Tools.java
Fri Oct  5 13:45:39 2007
@@ -60,6 +60,27 @@
         return name.replace('.', '/') + '/';
     }
 
+    public static void checkDeadLoop(Component c, int[] count) {
+        final int DEAD_LOOP_TIMEOUT = 1000;
+        final int VALID_NUMBER_OF_PAINT_CALLS = 5;
+        
+        Frame f = new Frame();
+        
+        f.add(c);
+        f.setSize(300,200);
+        f.setVisible(true);
+
+        try {
+            Thread.sleep(DEAD_LOOP_TIMEOUT);
+        } catch (Exception e) {}
+        
+        f.dispose();
+        
+        Assert.assertTrue("paint() called " + count[0] +
+                " times, a dead loop occurred",
+                count[0] <= VALID_NUMBER_OF_PAINT_CALLS);        
+    }
+
     public static class Shape {
 
         static int pointCount[] = {
@@ -674,4 +695,5 @@
         }
 
     }
+
 }



Mime
View raw message