diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp index d5bbdc51b0b46..0e7e27b5e8cf8 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp @@ -2498,32 +2498,22 @@ jint AwtWindow::_GetScreenImOn(void *param) jobject self = (jobject)param; - // It's entirely possible that our native resources have been destroyed - // before our java peer - if we're dispose()d, for instance. - // Alert caller w/ IllegalComponentStateException. - if (self == NULL) { - JNU_ThrowByName(env, "java/awt/IllegalComponentStateException", - "Peer null in JNI"); - return 0; - } - PDATA pData = JNI_GET_PDATA(self); - if (pData == NULL) { - JNU_ThrowByName(env, "java/awt/IllegalComponentStateException", - "Native resources unavailable"); - env->DeleteGlobalRef(self); - return 0; - } + jint result = -1; + AwtWindow* window = NULL; - jint result = 0; - AwtWindow *w = (AwtWindow *)pData; - if (::IsWindow(w->GetHWnd())) + // Our native resources may have been destroyed before the Java peer, + // e.g., if dispose() was called. In that case, return the default screen. + PDATA pData; + JNI_CHECK_PEER_GOTO(self, ret); + window = (AwtWindow *)pData; + if (::IsWindow(window->GetHWnd())) { - result = (jint)w->GetScreenImOn(); + result = (jint)window->GetScreenImOn(); } + ret: env->DeleteGlobalRef(self); - - return result; + return (result != -1) ? result : AwtWin32GraphicsDevice::GetDefaultDeviceIndex(); } void AwtWindow::_SetFocusableWindow(void *param) diff --git a/test/jdk/java/awt/Frame/BogusFocusableWindowState/BogusFocusableWindowState.java b/test/jdk/java/awt/Frame/BogusFocusableWindowState/BogusFocusableWindowState.java new file mode 100644 index 0000000000000..64621796b4f63 --- /dev/null +++ b/test/jdk/java/awt/Frame/BogusFocusableWindowState/BogusFocusableWindowState.java @@ -0,0 +1,50 @@ +/* + * Copyright Amazon.com Inc. 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.Window; + +/** + * @test + * @bug 8346952 + * @summary Verifies no exception occurs when triggering updateCG() + * for an ownerless window. + * @key headful + */ +public final class BogusFocusableWindowState { + + public static void main(String[] args) { + Window frame = new Window(null) { + @Override + public boolean getFocusableWindowState() { + removeNotify(); + return true; + } + }; + try { + frame.pack(); + frame.setVisible(true); + } finally { + frame.dispose(); + } + } +} diff --git a/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java b/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java index 96febfb6744e5..52961d2827f4a 100644 --- a/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java +++ b/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java @@ -27,7 +27,7 @@ /** * @test - * @bug 8235638 8235739 8285094 + * @bug 8235638 8235739 8285094 8346952 * @key headful */ public final class GetGraphicsStressTest {