Skip to content

Commit 44cff9d

Browse files
anass-bayamrserb
authored andcommitted
8346952: GetGraphicsStressTest.java fails: Native resources unavailable
Reviewed-by: serb
1 parent 3bcbcc5 commit 44cff9d

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

src/java.desktop/windows/native/libawt/windows/awt_Window.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,32 +2498,22 @@ jint AwtWindow::_GetScreenImOn(void *param)
24982498

24992499
jobject self = (jobject)param;
25002500

2501-
// It's entirely possible that our native resources have been destroyed
2502-
// before our java peer - if we're dispose()d, for instance.
2503-
// Alert caller w/ IllegalComponentStateException.
2504-
if (self == NULL) {
2505-
JNU_ThrowByName(env, "java/awt/IllegalComponentStateException",
2506-
"Peer null in JNI");
2507-
return 0;
2508-
}
2509-
PDATA pData = JNI_GET_PDATA(self);
2510-
if (pData == NULL) {
2511-
JNU_ThrowByName(env, "java/awt/IllegalComponentStateException",
2512-
"Native resources unavailable");
2513-
env->DeleteGlobalRef(self);
2514-
return 0;
2515-
}
2501+
jint result = -1;
2502+
AwtWindow* window = NULL;
25162503

2517-
jint result = 0;
2518-
AwtWindow *w = (AwtWindow *)pData;
2519-
if (::IsWindow(w->GetHWnd()))
2504+
// Our native resources may have been destroyed before the Java peer,
2505+
// e.g., if dispose() was called. In that case, return the default screen.
2506+
PDATA pData;
2507+
JNI_CHECK_PEER_GOTO(self, ret);
2508+
window = (AwtWindow *)pData;
2509+
if (::IsWindow(window->GetHWnd()))
25202510
{
2521-
result = (jint)w->GetScreenImOn();
2511+
result = (jint)window->GetScreenImOn();
25222512
}
25232513

2514+
ret:
25242515
env->DeleteGlobalRef(self);
2525-
2526-
return result;
2516+
return (result != -1) ? result : AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
25272517
}
25282518

25292519
void AwtWindow::_SetFocusableWindow(void *param)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Window;
25+
26+
/**
27+
* @test
28+
* @bug 8346952
29+
* @summary Verifies no exception occurs when triggering updateCG()
30+
* for an ownerless window.
31+
* @key headful
32+
*/
33+
public final class BogusFocusableWindowState {
34+
35+
public static void main(String[] args) {
36+
Window frame = new Window(null) {
37+
@Override
38+
public boolean getFocusableWindowState() {
39+
removeNotify();
40+
return true;
41+
}
42+
};
43+
try {
44+
frame.pack();
45+
frame.setVisible(true);
46+
} finally {
47+
frame.dispose();
48+
}
49+
}
50+
}

test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* @test
30-
* @bug 8235638 8235739 8285094
30+
* @bug 8235638 8235739 8285094 8346952
3131
* @key headful
3232
*/
3333
public final class GetGraphicsStressTest {

0 commit comments

Comments
 (0)