--- old/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java 2016-02-18 12:17:02.421527001 +0300 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java 2016-02-18 12:17:02.297527005 +0300 @@ -266,14 +266,17 @@ return null; } - if (wm_set_insets != null) { + if (wm_set_insets != null && !isNull(wm_set_insets)) { return wm_set_insets; } if (changedAtom == null) { wm_set_insets = XWM.getInsetsFromExtents(getWindow()); } else { - wm_set_insets = XWM.getInsetsFromProp(getWindow(), changedAtom); + Insets insets = XWM.getInsetsFromProp(getWindow(), changedAtom); + if (insets != null && !isNull(insets)) { + wm_set_insets = insets; + } } if (insLog.isLoggable(PlatformLogger.Level.FINER)) { @@ -345,7 +348,7 @@ // Check if we have insets provided by the WM Insets correctWM = getWMSetInsets(null); - if (correctWM != null) { + if (correctWM != null && !isNull(correctWM)) { if (insLog.isLoggable(PlatformLogger.Level.FINER)) { insLog.finer("wm-provided insets {0}", correctWM); } @@ -370,7 +373,7 @@ } } - if (correctWM != null) { + if (correctWM != null && !isNull(correctWM)) { handleCorrectInsets(correctWM); } } @@ -398,12 +401,20 @@ //smaller size is specified in setSize(), XToolkit //update minimum size hints updateMinSizeHints(); + } else { + return; } if (insLog.isLoggable(PlatformLogger.Level.FINER)) { insLog.finer("Dimensions before reparent: " + dimensions); } - dimensions.setInsets(getRealInsets()); + dimensions.setInsets(correctWM); + if (dimensions.isClientSizeSet()) { + Dimension cs = dimensions.getClientSize(); + dimensions.setClientSize( + cs.width - correction.left - correction.right, + cs.height - correction.top - correction.bottom); + } insets_corrected = true; if (isMaximized()) { @@ -716,7 +727,7 @@ return; } //Last chance to correct insets - if (!insets_corrected && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) { + if (getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) { long parent = XlibUtil.getParentWindow(window); Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null; if (insLog.isLoggable(PlatformLogger.Level.FINER)) { @@ -726,7 +737,7 @@ insLog.finer("Configure notify - insets are still not available"); } } - if (correctWM != null) { + if (correctWM != null && !isNull(correctWM)) { handleCorrectInsets(correctWM); } else { //Only one attempt to correct insets is made (to lower risk) --- /dev/null 2016-02-18 10:26:55.033760309 +0300 +++ new/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 2016-02-18 12:17:02.581526995 +0300 @@ -0,0 +1,66 @@ +/* + * 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(100); + frame.setLocation(321, 321); + robot.waitForIdle(); + robot.delay(100); + Dimension size = frame.getSize(); + if(size.width != 200 || size.height != 200) { + frame.dispose(); + throw new RuntimeException("getSize() is wrong " + size); + } + Rectangle r = frame.getBounds(); + frame.dispose(); + if(r.x != 321 || r.y != 321) { + throw new RuntimeException("getLocation() returns " + + "wrong coordinates " + r.getLocation()); + } + if(r.width != 200 || r.height != 200) { + throw new RuntimeException("getSize() is wrong " + r.getSize()); + } + } + System.out.println("ok"); + } + +} \ No newline at end of file