7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
authorserb
Thu, 24 Oct 2013 14:32:07 +0400
changeset 21270 8a0fc12b81a2
parent 21269 4113e17e5db3
child 21271 62d0e22ef687
7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError Reviewed-by: anthony, art
jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java
jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java
jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java
jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
jdk/src/solaris/classes/sun/awt/X11/XContentWindow.java
jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java
jdk/src/solaris/classes/sun/awt/X11/XListPeer.java
jdk/src/solaris/classes/sun/awt/X11/XWindow.java
jdk/test/java/awt/Paint/ButtonRepaint.java
jdk/test/java/awt/Paint/CheckboxRepaint.java
jdk/test/java/awt/Paint/ExposeOnEDT.java
jdk/test/java/awt/Paint/LabelRepaint.java
jdk/test/java/awt/Paint/ListRepaint.java
--- a/jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2013, 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
@@ -79,10 +79,17 @@
         return true;
     }
 
-    public void  setLabel(java.lang.String label) {
-        this.label = label;
-        repaint();
+    @Override
+    public void setLabel(String label) {
+        if (label == null) {
+            label = "";
+        }
+        if (!label.equals(this.label)) {
+            this.label = label;
+            repaint();
+        }
     }
+
     public void setBackground(Color c) {
         updateMotifColors(c);
         super.setBackground(c);
@@ -257,10 +264,6 @@
         drawMotif3DRect(g, x, y, w-1, h-1, pressed);
     }
 
-    public void setFont(Font f) {
-        super.setFont(f);
-        target.repaint();
-    }
     protected void paintFocus(Graphics g, int x, int y, int w, int h){
         g.setColor(focusColor);
         g.drawRect(x,y,w,h);
--- a/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -103,15 +103,4 @@
     protected boolean doEraseBackground() {
         return !eraseBackgroundDisabled;
     }
-    public void setBackground(Color c) {
-        boolean doRepaint = false;
-        if( getPeerBackground() == null ||
-           !getPeerBackground().equals( c ) ) {
-            doRepaint = true;
-        }
-        super.setBackground(c);
-        if( doRepaint ) {
-            target.repaint();
-        }
-    }
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -31,6 +31,7 @@
 import java.awt.image.BufferedImage;
 import javax.swing.plaf.basic.BasicGraphicsUtils;
 import java.awt.geom.AffineTransform;
+import java.util.Objects;
 
 import sun.util.logging.PlatformLogger;
 
@@ -135,14 +136,16 @@
 
     public void keyReleased(KeyEvent e) {}
 
-    public void  setLabel(java.lang.String label) {
-        if ( label == null ) {
-            this.label = "";
-        } else {
+    @Override
+    public void setLabel(String label) {
+        if (label == null) {
+            label = "";
+        }
+        if (!label.equals(this.label)) {
             this.label = label;
+            layout();
+            repaint();
         }
-        layout();
-        repaint();
     }
 
     void handleJavaMouseEvent(MouseEvent e) {
@@ -377,10 +380,6 @@
             g.drawImage(buffer, x, y, null);
         }
     }
-    public void setFont(Font f) {
-        super.setFont(f);
-        target.repaint();
-    }
 
     public void paintRadioButton(Graphics g, int x, int y, int w, int h) {
 
@@ -424,16 +423,21 @@
         g.drawRect(x,y,w,h);
     }
 
+    @Override
     public void setState(boolean state) {
         if (selected != state) {
             selected = state;
             repaint();
         }
     }
-    public void setCheckboxGroup(CheckboxGroup g) {
-        // If changed from grouped/ungrouped, need to repaint()
-        checkBoxGroup = g;
-        repaint();
+
+    @Override
+    public void setCheckboxGroup(final CheckboxGroup g) {
+        if (!Objects.equals(g, checkBoxGroup)) {
+            // If changed from grouped/ungrouped, need to repaint()
+            checkBoxGroup = g;
+            repaint();
+        }
     }
 
     // NOTE: This method is called by privileged threads.
--- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -61,6 +61,7 @@
 import java.lang.reflect.*;
 import java.security.*;
 import java.util.Collection;
+import java.util.Objects;
 import java.util.Set;
 import sun.util.logging.PlatformLogger;
 import sun.awt.*;
@@ -635,22 +636,30 @@
         g.drawLine(x+width, y+height, x+width, y+1);  // right
     }
 
+    @Override
     public void setBackground(Color c) {
         if (log.isLoggable(PlatformLogger.Level.FINE)) {
             log.fine("Set background to " + c);
         }
         synchronized (getStateLock()) {
+            if (Objects.equals(background, c)) {
+                return;
+            }
             background = c;
         }
         super.setBackground(c);
         repaint();
     }
 
+    @Override
     public void setForeground(Color c) {
         if (log.isLoggable(PlatformLogger.Level.FINE)) {
             log.fine("Set foreground to " + c);
         }
         synchronized (getStateLock()) {
+            if (Objects.equals(foreground, c)) {
+                return;
+            }
             foreground = c;
         }
         repaint();
@@ -674,18 +683,21 @@
         return sun.font.FontDesignMetrics.getMetrics(font);
     }
 
+    @Override
     public void setFont(Font f) {
+        if (f == null) {
+            f = XWindow.getDefaultFont();
+        }
         synchronized (getStateLock()) {
-            if (f == null) {
-                f = XWindow.getDefaultFont();
+            if (f.equals(font)) {
+                return;
             }
             font = f;
         }
-        // as it stands currently we dont need to do layout or repaint since
+        // as it stands currently we dont need to do layout since
         // layout is done in the Component upon setFont.
         //layout();
-        // target.repaint();
-        //repaint()?
+        repaint();
     }
 
     public Font getFont() {
--- a/jdk/src/solaris/classes/sun/awt/X11/XContentWindow.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XContentWindow.java	Thu Oct 24 14:32:07 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, 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
@@ -142,7 +142,7 @@
     }
 
 
-    public void handleExposeEvent(Component target, int x, int y, int w, int h) {
+    public void postPaintEvent(Component target, int x, int y, int w, int h) {
         // TODO: ?
         // get rid of 'istanceof' by subclassing:
         // XContentWindow -> XFrameContentWindow
@@ -160,13 +160,13 @@
             iconifiedExposeEvents.add(new SavedExposeEvent(target, x, y, w, h));
         } else {
             // Normal case: [it is not a frame or] the frame is not iconified.
-            super.handleExposeEvent(target, x, y, w, h);
+            super.postPaintEvent(target, x, y, w, h);
         }
     }
 
     void purgeIconifiedExposeEvents() {
         for (SavedExposeEvent evt : iconifiedExposeEvents) {
-            super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h);
+            super.postPaintEvent(evt.target, evt.x, evt.y, evt.w, evt.h);
         }
         iconifiedExposeEvents.clear();
     }
--- a/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2013, 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
@@ -132,20 +132,22 @@
         }
     }
 
-    public void setText(String text) {
-        label = text;
+    @Override
+    public void setText(String label) {
         if (label == null) {
             label = "";
         }
-        repaint();
-    }
-    public void setFont(Font f) {
-        super.setFont(f);
-        repaint();
+        if (!label.equals(this.label)) {
+            this.label = label;
+            repaint();
+        }
     }
 
-    public void setAlignment(int align) {
-        alignment = align;
-        repaint();
+    @Override
+    public void setAlignment(final int alignment) {
+        if (this.alignment != alignment) {
+            this.alignment = alignment;
+            repaint();
+        }
     }
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XListPeer.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XListPeer.java	Thu Oct 24 14:32:07 2013 +0400
@@ -31,8 +31,8 @@
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.peer.*;
+import java.util.Objects;
 import java.util.Vector;
-import java.awt.geom.*;
 import java.awt.image.*;
 import sun.util.logging.PlatformLogger;
 
@@ -409,7 +409,7 @@
         if (g != null) {
             try {
                 painter.paint(g, firstItem, lastItem, options, source, distance);
-                target.paint(g);
+                postPaintEvent(target, 0, 0, getWidth(), getHeight());
             } finally {
                 g.dispose();
             }
@@ -1682,11 +1682,13 @@
      * The bug is due to incorrent caching of the list item size
      * So we should recalculate font metrics on setFont
      */
-    public void setFont(Font f){
-        super.setFont(f);
-        initFontMetrics();
-        layout();
-        repaint();
+    public void setFont(Font f) {
+        if (!Objects.equals(getFont(), f)) {
+            super.setFont(f);
+            initFontMetrics();
+            layout();
+            repaint();
+        }
     }
 
     /**
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Wed Oct 23 16:24:50 2013 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Thu Oct 24 14:32:07 2013 +0400
@@ -32,7 +32,6 @@
 
 import java.lang.ref.WeakReference;
 
-import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 
 import sun.util.logging.PlatformLogger;
@@ -491,33 +490,31 @@
     public boolean isEmbedded() {
         return embedded;
     }
-    public  void repaint(int x,int y, int width, int height) {
+
+    public final void repaint(int x, int y, int width, int height) {
         if (!isVisible() || getWidth() == 0 || getHeight() == 0) {
             return;
         }
         Graphics g = getGraphics();
         if (g != null) {
             try {
-                g.setClip(x,y,width,height);
-                paint(g);
+                g.setClip(x, y, width, height);
+                if (SunToolkit.isDispatchThreadForAppContext(getTarget())) {
+                    paint(g); // The native and target will be painted in place.
+                } else {
+                    paintPeer(g);
+                    postPaintEvent(target, x, y, width, height);
+                }
             } finally {
                 g.dispose();
             }
         }
     }
+
     void repaint() {
-        if (!isVisible() || getWidth() == 0 || getHeight() == 0) {
-            return;
-        }
-        final Graphics g = getGraphics();
-        if (g != null) {
-            try {
-                paint(g);
-            } finally {
-                g.dispose();
-            }
-        }
+        repaint(0, 0, getWidth(), getHeight());
     }
+
     public void paint(final Graphics g) {
         // paint peer
         paintPeer(g);
@@ -558,11 +555,11 @@
             && compAccessor.getWidth(target) != 0
             && compAccessor.getHeight(target) != 0)
         {
-            handleExposeEvent(target, x, y, w, h);
+            postPaintEvent(target, x, y, w, h);
         }
     }
 
-    public void handleExposeEvent(Component target, int x, int y, int w, int h) {
+    public void postPaintEvent(Component target, int x, int y, int w, int h) {
         PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
             createPaintEvent(target, x, y, w, h);
         if (event != null) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Paint/ButtonRepaint.java	Thu Oct 24 14:32:07 2013 +0400
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import java.awt.*;
+import java.awt.peer.ButtonPeer;
+
+/**
+ * @test
+ * @bug 7090424
+ * @author Sergey Bylokhov
+ */
+public final class ButtonRepaint extends Button {
+
+    public static void main(final String[] args) {
+        for (int i = 0; i < 10; ++i) {
+            final Frame frame = new Frame();
+            frame.setSize(300, 300);
+            frame.setLocationRelativeTo(null);
+            ButtonRepaint button = new ButtonRepaint();
+            frame.add(button);
+            frame.setVisible(true);
+            sleep();
+            button.test();
+            frame.dispose();
+        }
+    }
+
+    private static void sleep() {
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException ignored) {
+        }
+    }
+
+    @Override
+    public void paint(final Graphics g) {
+        super.paint(g);
+        if (!EventQueue.isDispatchThread()) {
+            throw new RuntimeException("Wrong thread");
+        }
+        test();
+    }
+
+    void test() {
+        setLabel("");
+        setLabel(null);
+        setLabel(getLabel());
+        ((ButtonPeer) getPeer()).setLabel("");
+        ((ButtonPeer) getPeer()).setLabel(null);
+        ((ButtonPeer) getPeer()).setLabel(getLabel());
+
+        setFont(null);
+        setFont(getFont());
+        getPeer().setFont(getFont());
+
+        setBackground(null);
+        setBackground(getBackground());
+        getPeer().setBackground(getBackground());
+
+        setForeground(null);
+        setForeground(getForeground());
+        getPeer().setForeground(getForeground());
+
+        setEnabled(isEnabled());
+        getPeer().setEnabled(isEnabled());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Paint/CheckboxRepaint.java	Thu Oct 24 14:32:07 2013 +0400
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2013, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.peer.CheckboxPeer;
+
+/**
+ * @test
+ * @bug 7090424
+ * @author Sergey Bylokhov
+ */
+public final class CheckboxRepaint extends Checkbox {
+
+    public static void main(final String[] args) {
+        for (int i = 0; i < 10; ++i) {
+            final Frame frame = new Frame();
+            frame.setSize(300, 300);
+            frame.setLocationRelativeTo(null);
+            CheckboxRepaint checkbox = new CheckboxRepaint();
+            frame.add(checkbox);
+            frame.setVisible(true);
+            sleep();
+            checkbox.test();
+            frame.dispose();
+        }
+    }
+
+    private static void sleep() {
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException ignored) {
+        }
+    }
+
+    @Override
+    public void paint(final Graphics g) {
+        super.paint(g);
+        if (!EventQueue.isDispatchThread()) {
+            throw new RuntimeException("Wrong thread");
+        }
+        test();
+    }
+
+    void test() {
+        setState(getState());
+        ((CheckboxPeer) getPeer()).setState(getState());
+
+        setCheckboxGroup(getCheckboxGroup());
+        ((CheckboxPeer) getPeer()).setCheckboxGroup(getCheckboxGroup());
+
+        setLabel("");
+        setLabel(null);
+        setLabel(getLabel());
+        ((CheckboxPeer) getPeer()).setLabel("");
+        ((CheckboxPeer) getPeer()).setLabel(null);
+        ((CheckboxPeer) getPeer()).setLabel(getLabel());
+
+        setFont(null);
+        setFont(getFont());
+        getPeer().setFont(getFont());
+
+        setBackground(null);
+        setBackground(getBackground());
+        getPeer().setBackground(getBackground());
+
+        setForeground(null);
+        setForeground(getForeground());
+        getPeer().setForeground(getForeground());
+
+        setEnabled(isEnabled());
+        getPeer().setEnabled(isEnabled());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Paint/ExposeOnEDT.java	Thu Oct 24 14:32:07 2013 +0400
@@ -0,0 +1,293 @@
+/*
+ * Copyright (c) 2013, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import sun.awt.SunToolkit;
+
+import java.awt.*;
+
+/**
+ * @test
+ * @bug 7090424
+ * @author Sergey Bylokhov
+ * @run main ExposeOnEDT
+ */
+public final class ExposeOnEDT {
+
+    private static final Button buttonStub = new Button() {
+        @Override
+        public void paint(final Graphics g) {
+            buttonPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Canvas canvasStub = new Canvas() {
+        @Override
+        public void paint(final Graphics g) {
+            canvasPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Checkbox checkboxStub = new Checkbox() {
+        @Override
+        public void paint(final Graphics g) {
+            checkboxPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Choice choiceStub = new Choice() {
+        @Override
+        public void paint(final Graphics g) {
+            choicePainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Component lwComponentStub = new Component() {
+        @Override
+        public void paint(final Graphics g) {
+            lwPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Container containerStub = new Container() {
+        @Override
+        public void paint(final Graphics g) {
+            containerPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Frame frame = new Frame() {
+        @Override
+        public void paint(final Graphics g) {
+            super.paint(g);
+            framePainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Label labelStub = new Label() {
+        @Override
+        public void paint(final Graphics g) {
+            labelPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final List listStub = new List() {
+        @Override
+        public void paint(final Graphics g) {
+            listPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Panel panelStub = new Panel() {
+        @Override
+        public void paint(final Graphics g) {
+            panelPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final Scrollbar scrollbarStub = new Scrollbar() {
+        @Override
+        public void paint(final Graphics g) {
+            scrollbarPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final ScrollPane scrollPaneStub = new ScrollPane() {
+        @Override
+        public void paint(final Graphics g) {
+            scrollPanePainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final TextArea textAreaStub = new TextArea() {
+        @Override
+        public void paint(final Graphics g) {
+            textAreaPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static final TextField textFieldStub = new TextField() {
+        @Override
+        public void paint(final Graphics g) {
+            textFieldPainted = true;
+            if (!EventQueue.isDispatchThread()) {
+                throw new RuntimeException("Wrong thread");
+            }
+        }
+    };
+    private static volatile boolean lwPainted;
+    private static volatile boolean buttonPainted;
+    private static volatile boolean canvasPainted;
+    private static volatile boolean checkboxPainted;
+    private static volatile boolean choicePainted;
+    private static volatile boolean containerPainted;
+    private static volatile boolean framePainted;
+    private static volatile boolean labelPainted;
+    private static volatile boolean listPainted;
+    private static volatile boolean panelPainted;
+    private static volatile boolean scrollbarPainted;
+    private static volatile boolean scrollPanePainted;
+    private static volatile boolean textAreaPainted;
+    private static volatile boolean textFieldPainted;
+
+    public static void main(final String[] args) throws Exception {
+        //Frame initialisation
+        frame.setLayout(new GridLayout());
+        frame.setSize(new Dimension(200, 200));
+        frame.setLocationRelativeTo(null);
+        frame.setVisible(true);
+        sleep();
+
+        frame.add(buttonStub);
+        frame.add(canvasStub);
+        frame.add(checkboxStub);
+        frame.add(choiceStub);
+        frame.add(lwComponentStub);
+        frame.add(containerStub);
+        frame.add(labelStub);
+        frame.add(listStub);
+        frame.add(panelStub);
+        frame.add(scrollbarStub);
+        frame.add(scrollPaneStub);
+        frame.add(textAreaStub);
+        frame.add(textFieldStub);
+        frame.validate();
+        sleep();
+
+        // Force expose event from the native system.
+        initPaintedFlags();
+        frame.setSize(300, 300);
+        frame.validate();
+        sleep();
+
+        //Check results.
+        validation();
+
+        cleanup();
+    }
+
+    private static void initPaintedFlags() {
+        lwPainted = false;
+        buttonPainted = false;
+        canvasPainted = false;
+        checkboxPainted = false;
+        choicePainted = false;
+        containerPainted = false;
+        framePainted = false;
+        labelPainted = false;
+        listPainted = false;
+        panelPainted = false;
+        scrollbarPainted = false;
+        scrollPanePainted = false;
+        textAreaPainted = false;
+        textFieldPainted = false;
+    }
+
+    private static void validation() {
+        if (!buttonPainted) {
+            fail("Paint is not called a Button ");
+        }
+        if (!canvasPainted) {
+            fail("Paint is not called a Canvas ");
+        }
+        if (!checkboxPainted) {
+            fail("Paint is not called a Checkbox ");
+        }
+        if (!choicePainted) {
+            fail("Paint is not called a Choice ");
+        }
+        if (!lwPainted) {
+            fail("Paint is not called on a lightweight");
+        }
+        if (!containerPainted) {
+            fail("Paint is not called on a Container");
+        }
+        if (!labelPainted) {
+            fail("Paint is not called on a Label");
+        }
+        if (!listPainted) {
+            fail("Paint is not called on a List");
+        }
+        if (!panelPainted) {
+            fail("Paint is not called on a Panel");
+        }
+        if (!scrollbarPainted) {
+            fail("Paint is not called on a Scrollbar");
+        }
+        if (!scrollPanePainted) {
+            fail("Paint is not called on a ScrollPane");
+        }
+        if (!textAreaPainted) {
+            fail("Paint is not called on a TextArea");
+        }
+        if (!textFieldPainted) {
+            fail("Paint is not called on a TextField");
+        }
+        if (!framePainted) {
+            fail("Paint is not called on a Frame when paintAll()");
+        }
+    }
+
+    private static void sleep() {
+        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+        try {
+            Thread.sleep(1000L);
+        } catch (InterruptedException ignored) {
+        }
+    }
+
+    private static void fail(final String message) {
+        cleanup();
+        throw new RuntimeException(message);
+    }
+
+    private static void cleanup() {
+        frame.dispose();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Paint/LabelRepaint.java	Thu Oct 24 14:32:07 2013 +0400
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2013, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Label;
+import java.awt.peer.LabelPeer;
+
+/**
+ * @test
+ * @bug 7090424
+ * @author Sergey Bylokhov
+ */
+public final class LabelRepaint extends Label {
+
+    public static void main(final String[] args) {
+        for (int i = 0; i < 10; ++i) {
+            final Frame frame = new Frame();
+            frame.setSize(300, 300);
+            frame.setLocationRelativeTo(null);
+            LabelRepaint label = new LabelRepaint();
+            frame.add(label);
+            frame.setVisible(true);
+            sleep();
+            label.test();
+            frame.dispose();
+        }
+    }
+
+    private static void sleep() {
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException ignored) {
+        }
+    }
+
+    @Override
+    public void paint(final Graphics g) {
+        super.paint(g);
+        if (!EventQueue.isDispatchThread()) {
+            throw new RuntimeException("Wrong thread");
+        }
+        test();
+    }
+
+    void test() {
+        setAlignment(getAlignment());
+        ((LabelPeer) getPeer()).setAlignment(getAlignment());
+
+        setText("");
+        setText(null);
+        setText(getText());
+        ((LabelPeer) getPeer()).setText("");
+        ((LabelPeer) getPeer()).setText(null);
+        ((LabelPeer) getPeer()).setText(getText());
+
+        setFont(null);
+        setFont(getFont());
+        getPeer().setFont(getFont());
+
+        setBackground(null);
+        setBackground(getBackground());
+        getPeer().setBackground(getBackground());
+
+        setForeground(null);
+        setForeground(getForeground());
+        getPeer().setForeground(getForeground());
+
+        setEnabled(isEnabled());
+        getPeer().setEnabled(isEnabled());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Paint/ListRepaint.java	Thu Oct 24 14:32:07 2013 +0400
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2013, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.List;
+import java.awt.peer.ListPeer;
+
+/**
+ * @test
+ * @bug 7090424
+ * @author Sergey Bylokhov
+ */
+public final class ListRepaint extends List {
+
+    public static void main(final String[] args) {
+        for (int i = 0; i < 10; ++i) {
+            final Frame frame = new Frame();
+            frame.setSize(300, 300);
+            frame.setLocationRelativeTo(null);
+            ListRepaint list = new ListRepaint();
+            list.add("1");
+            list.add("2");
+            list.add("3");
+            list.add("4");
+            list.select(0);
+            frame.add(list);
+            frame.setVisible(true);
+            sleep();
+            list.test();
+            frame.dispose();
+        }
+    }
+
+    private static void sleep() {
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException ignored) {
+        }
+    }
+
+    @Override
+    public void paint(final Graphics g) {
+        super.paint(g);
+        if (!EventQueue.isDispatchThread()) {
+            throw new RuntimeException("Wrong thread");
+        }
+        test();
+    }
+
+    void test() {
+        select(0);
+        ((ListPeer) getPeer()).select(getSelectedIndex());
+
+        setFont(null);
+        setFont(getFont());
+        getPeer().setFont(getFont());
+
+        setBackground(null);
+        setBackground(getBackground());
+        getPeer().setBackground(getBackground());
+
+        setForeground(null);
+        setForeground(getForeground());
+        getPeer().setForeground(getForeground());
+
+        setEnabled(isEnabled());
+        getPeer().setEnabled(isEnabled());
+    }
+}