From b5d2e25478c6a8b6f3d8aae71f8a6745a11b1c9e Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Fri, 11 Apr 2025 11:32:42 +0000 Subject: [PATCH] 8354189: Remove JLI_ReportErrorMessageSys on Windows Reviewed-by: alanb, mdoerr --- src/java.base/share/native/libjli/java.h | 6 +- src/java.base/unix/native/libjli/java_md.h | 6 +- src/java.base/windows/native/libjli/java_md.c | 71 +------------------ 3 files changed, 7 insertions(+), 76 deletions(-) diff --git a/src/java.base/share/native/libjli/java.h b/src/java.base/share/native/libjli/java.h index f39e923cab8..5586cef5cbc 100644 --- a/src/java.base/share/native/libjli/java.h +++ b/src/java.base/share/native/libjli/java.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -125,10 +125,6 @@ void CreateExecutionEnvironment(int *argc, char ***argv, JNIEXPORT void JNICALL JLI_ReportErrorMessage(const char * message, ...); -/* Reports a system error message to stderr or a window */ -JNIEXPORT void JNICALL -JLI_ReportErrorMessageSys(const char * message, ...); - /* Reports an error message only to stderr. */ JNIEXPORT void JNICALL JLI_ReportMessage(const char * message, ...); diff --git a/src/java.base/unix/native/libjli/java_md.h b/src/java.base/unix/native/libjli/java_md.h index eb5a66a8489..55c125db0c7 100644 --- a/src/java.base/unix/native/libjli/java_md.h +++ b/src/java.base/unix/native/libjli/java_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -59,6 +59,10 @@ static jboolean GetJVMPath(const char *jdkroot, const char *jvmtype, char *jvmpath, jint jvmpathsize); static jboolean GetJDKInstallRoot(char *path, jint pathsize, jboolean speculative); +/* Reports a system error message to stderr, including errno */ +JNIEXPORT void JNICALL +JLI_ReportErrorMessageSys(const char * message, ...); + #if defined(_AIX) jboolean GetApplicationHomeFromLibpath(char *buf, jint bufsize); #include "java_md_aix.h" diff --git a/src/java.base/windows/native/libjli/java_md.c b/src/java.base/windows/native/libjli/java_md.c index 77d48fecca0..bf1cb0c0db5 100644 --- a/src/java.base/windows/native/libjli/java_md.c +++ b/src/java.base/windows/native/libjli/java_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, 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 @@ -570,75 +570,6 @@ JLI_ReportErrorMessage(const char* fmt, ...) { va_end(vl); } -/* - * Just like JLI_ReportErrorMessage, except that it concatenates the system - * error message if any, it's up to the calling routine to correctly - * format the separation of the messages. - */ -JNIEXPORT void JNICALL -JLI_ReportErrorMessageSys(const char *fmt, ...) -{ - va_list vl; - - int save_errno = errno; - DWORD errval; - jboolean freeit = JNI_FALSE; - char *errtext = NULL; - - va_start(vl, fmt); - - if ((errval = GetLastError()) != 0) { /* Platform SDK / DOS Error */ - int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM| - FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, errval, 0, (LPTSTR)&errtext, 0, NULL); - if (errtext == NULL || n == 0) { /* Paranoia check */ - errtext = ""; - n = 0; - } else { - freeit = JNI_TRUE; - if (n > 2) { /* Drop final CR, LF */ - if (errtext[n - 1] == '\n') n--; - if (errtext[n - 1] == '\r') n--; - errtext[n] = '\0'; - } - } - } else { /* C runtime error that has no corresponding DOS error code */ - errtext = strerror(save_errno); - } - - if (IsJavaw()) { - char *message; - int mlen; - /* get the length of the string we need */ - int len = mlen = _vscprintf(fmt, vl) + 1; - if (freeit) { - mlen += (int)JLI_StrLen(errtext); - } - - message = (char *)JLI_MemAlloc(mlen); - _vsnprintf(message, len, fmt, vl); - message[len]='\0'; - - if (freeit) { - JLI_StrCat(message, errtext); - } - - MessageBox(NULL, message, "Java Virtual Machine Launcher", - (MB_OK|MB_ICONSTOP|MB_APPLMODAL)); - - JLI_MemFree(message); - } else { - vfprintf(stderr, fmt, vl); - if (freeit) { - fprintf(stderr, "%s", errtext); - } - } - if (freeit) { - (void)LocalFree((HLOCAL)errtext); - } - va_end(vl); -} - JNIEXPORT void JNICALL JLI_ReportExceptionDescription(JNIEnv * env) { if (IsJavaw()) {