--- old/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java 2015-10-05 14:03:12.000000000 +0300 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java 2015-10-05 14:03:12.000000000 +0300 @@ -41,6 +41,7 @@ private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XDecoratedPeer"); private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XDecoratedPeer"); private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XDecoratedPeer"); + private static final int MAX_INSET_ATTEMPT = 100; // Set to true when we get the first ConfigureNotify after being // reparented - indicates that WM has adopted the top-level. @@ -266,7 +267,7 @@ return null; } - if (wm_set_insets != null) { + if (!isNull(wm_set_insets)) { return wm_set_insets; } @@ -345,7 +346,12 @@ // Check if we have insets provided by the WM Insets correctWM = getWMSetInsets(null); - if (correctWM != null) { + int maxAttempts = MAX_INSET_ATTEMPT; + while (maxAttempts--> 0 && isNull(correctWM)) { + Thread.yield(); + correctWM = getWMSetInsets(null); + } + if (!isNull(correctWM)) { if (insLog.isLoggable(PlatformLogger.Level.FINER)) { insLog.finer("wm-provided insets {0}", correctWM); } @@ -370,8 +376,10 @@ } } - if (correctWM != null) { + if (!isNull(correctWM)) { handleCorrectInsets(correctWM); + } else { + insets_corrected = false; } } } finally { --- /dev/null 2015-10-05 08:38:53.498575016 +0300 +++ new/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 2015-10-05 14:03:13.000000000 +0300 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, 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. + */ + +/** + * @test @summary setAlwaysOnTop doesn't behave correctly in Linux/Solaris under + * certain scenarios + * @bug 8036915 + * @author Semyon Sadetsky + * @run main GetScreenLocationTest + */ +import java.awt.*; + +public class GetScreenLocationTest { + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + Window frame = null; + for(int i = 0; i < 100; i++) { + if(frame != null) frame.dispose(); + frame = new Dialog((Frame)null); + frame.setSize(200, 200); + frame.setVisible(true); + robot.waitForIdle(); + robot.delay(200); + frame.setLocation(500, 500); + robot.waitForIdle(); + robot.delay(100); + Point location = frame.getLocation(); + Dimension size = frame.getSize(); + frame.dispose(); + if(location.x != 500 || location.y != 500) { + throw new RuntimeException("getLocation() returns " + + "wrong coordinates " + location); + } + if(size.width != 200 || size.height != 200) { + throw new RuntimeException("getSize() is wrong " + size); + } + } + System.out.println("ok"); + } + +} \ No newline at end of file