Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
/ jdk22u Public archive

Commit

Permalink
8323664: java/awt/font/JNICheck/FreeTypeScalerJNICheck.java still fai…
Browse files Browse the repository at this point in the history
…ls with JNI warning on some Windows configurations

Backport-of: 99c9ae127c0a3b8c4fc6ede87079ff7c693a2905
  • Loading branch information
RealCLanger committed Feb 27, 2024
1 parent 5c08afe commit a44bfa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, 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
Expand Down Expand Up @@ -153,21 +153,20 @@ AwtDebugSupport::~AwtDebugSupport() {
static jboolean isHeadless() {
jmethodID headlessFn;
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jclass graphicsEnvClass = env->FindClass(
"java/awt/GraphicsEnvironment");
// be on the safe side and avoid JNI warnings by calling ExceptionCheck
// an accumulated exception is not cleared
env->ExceptionCheck();
jclass graphicsEnvClass = env->FindClass("java/awt/GraphicsEnvironment");

if (graphicsEnvClass != NULL) {
headlessFn = env->GetStaticMethodID(
graphicsEnvClass, "isHeadless", "()Z");
headlessFn = env->GetStaticMethodID(graphicsEnvClass, "isHeadless", "()Z");
if (headlessFn != NULL) {
return env->CallStaticBooleanMethod(graphicsEnvClass,
headlessFn);
return env->CallStaticBooleanMethod(graphicsEnvClass, headlessFn);
}
}
return true;
}


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

static char assertMsg[ASSERT_MSG_SIZE+1];
DWORD lastError = GetLastError();
LPSTR msgBuffer = NULL;
int ret = IDNO;
DWORD lastError = GetLastError();
LPSTR msgBuffer = NULL;
int ret = IDNO;
static jboolean headless = isHeadless();

DWORD fret= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
Expand Down
11 changes: 6 additions & 5 deletions test/jdk/java/awt/font/JNICheck/FreeTypeScalerJNICheck.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -45,7 +45,10 @@ public static void main(String[] args) throws Exception {
} else {
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder("-Xcheck:jni", FreeTypeScalerJNICheck.class.getName(), "runtest");
OutputAnalyzer oa = ProcessTools.executeProcess(pb);
oa.shouldContain("Done").shouldNotContain("WARNING").shouldHaveExitValue(0);
oa.shouldContain("Done")
.shouldNotContain("WARNING")
.shouldNotContain("AWT Assertion")
.shouldHaveExitValue(0);
}
}

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

for (String ff : families)
{
for (String ff : families) {
Font font = new Font(ff, Font.PLAIN, 12);
Rectangle2D bounds = font.getStringBounds("test", g2d.getFontRenderContext());
g2d.setFont(font);
Expand All @@ -66,4 +68,3 @@ public static void runTest() {
System.out.println("Done");
}
}

1 comment on commit a44bfa4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.