Skip to content

Commit 36b5ac4

Browse files
committed
8323664: java/awt/font/JNICheck/FreeTypeScalerJNICheck.java still fails with JNI warning on some Windows configurations
Backport-of: 99c9ae1
1 parent 4296ddf commit 36b5ac4

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -153,21 +153,20 @@ AwtDebugSupport::~AwtDebugSupport() {
153153
static jboolean isHeadless() {
154154
jmethodID headlessFn;
155155
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
156-
jclass graphicsEnvClass = env->FindClass(
157-
"java/awt/GraphicsEnvironment");
156+
// be on the safe side and avoid JNI warnings by calling ExceptionCheck
157+
// an accumulated exception is not cleared
158+
env->ExceptionCheck();
159+
jclass graphicsEnvClass = env->FindClass("java/awt/GraphicsEnvironment");
158160

159161
if (graphicsEnvClass != NULL) {
160-
headlessFn = env->GetStaticMethodID(
161-
graphicsEnvClass, "isHeadless", "()Z");
162+
headlessFn = env->GetStaticMethodID(graphicsEnvClass, "isHeadless", "()Z");
162163
if (headlessFn != NULL) {
163-
return env->CallStaticBooleanMethod(graphicsEnvClass,
164-
headlessFn);
164+
return env->CallStaticBooleanMethod(graphicsEnvClass, headlessFn);
165165
}
166166
}
167167
return true;
168168
}
169169

170-
171170
void AwtDebugSupport::AssertCallback(const char * expr, const char * file, int line) {
172171
static const int ASSERT_MSG_SIZE = 1024;
173172
static const char * AssertFmt =
@@ -177,9 +176,9 @@ void AwtDebugSupport::AssertCallback(const char * expr, const char * file, int l
177176
"Do you want to break into the debugger?";
178177

179178
static char assertMsg[ASSERT_MSG_SIZE+1];
180-
DWORD lastError = GetLastError();
181-
LPSTR msgBuffer = NULL;
182-
int ret = IDNO;
179+
DWORD lastError = GetLastError();
180+
LPSTR msgBuffer = NULL;
181+
int ret = IDNO;
183182
static jboolean headless = isHeadless();
184183

185184
DWORD fret= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |

test/jdk/java/awt/font/JNICheck/FreeTypeScalerJNICheck.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -45,7 +45,10 @@ public static void main(String[] args) throws Exception {
4545
} else {
4646
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder("-Xcheck:jni", FreeTypeScalerJNICheck.class.getName(), "runtest");
4747
OutputAnalyzer oa = ProcessTools.executeProcess(pb);
48-
oa.shouldContain("Done").shouldNotContain("WARNING").shouldHaveExitValue(0);
48+
oa.shouldContain("Done")
49+
.shouldNotContain("WARNING")
50+
.shouldNotContain("AWT Assertion")
51+
.shouldHaveExitValue(0);
4952
}
5053
}
5154

@@ -54,8 +57,7 @@ public static void runTest() {
5457
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
5558
Graphics2D g2d = bi.createGraphics();
5659

57-
for (String ff : families)
58-
{
60+
for (String ff : families) {
5961
Font font = new Font(ff, Font.PLAIN, 12);
6062
Rectangle2D bounds = font.getStringBounds("test", g2d.getFontRenderContext());
6163
g2d.setFont(font);
@@ -66,4 +68,3 @@ public static void runTest() {
6668
System.out.println("Done");
6769
}
6870
}
69-

0 commit comments

Comments
 (0)