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() {
153153static 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-
171170void 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 |
0 commit comments