allow NULL for msg in NET_ThrowNew

This commit is contained in:
Jaikiran Pai 2026-01-22 18:18:02 +05:30
parent e5e4c1ab59
commit 787823b8b0
3 changed files with 25 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, 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
@ -68,13 +68,14 @@ NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
void
NET_ThrowNew(JNIEnv *env, int errorNumber, char *msg) {
char fullMsg[512];
if (!msg) {
msg = "no further information";
}
switch(errorNumber) {
case EBADF:
jio_snprintf(fullMsg, sizeof(fullMsg), "socket closed: %s", msg);
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", fullMsg);
if (msg == NULL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
} else {
jio_snprintf(fullMsg, sizeof(fullMsg), "socket closed: %s", msg);
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", fullMsg);
}
break;
default:
errno = errorNumber;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, 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
@ -139,13 +139,6 @@ NET_ThrowNew(JNIEnv *env, int errorNum, char *msg)
return;
}
/*
* Default message text if not provided
*/
if (!msg) {
msg = "no further information";
}
/*
* Check table for known winsock errors
*/
@ -163,13 +156,22 @@ NET_ThrowNew(JNIEnv *env, int errorNum, char *msg)
*/
if (i < table_size) {
excP = (char *)winsock_errors[i].exc;
jio_snprintf(fullMsg, sizeof(fullMsg), "%s: %s",
(char *)winsock_errors[i].errString, msg);
if (msg == NULL) {
jio_snprintf(fullMsg, sizeof(fullMsg), "%s",
(char *)winsock_errors[i].errString);
} else {
jio_snprintf(fullMsg, sizeof(fullMsg), "%s: %s",
(char *)winsock_errors[i].errString, msg);
}
} else {
jio_snprintf(fullMsg, sizeof(fullMsg),
"Unrecognized Windows Sockets error: %d: %s",
errorNum, msg);
if (msg == NULL) {
jio_snprintf(fullMsg, sizeof(fullMsg),
"Unrecognized Windows Sockets error: %d", errorNum);
} else {
jio_snprintf(fullMsg, sizeof(fullMsg),
"Unrecognized Windows Sockets error: %d: %s",
errorNum, msg);
}
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2026, 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
@ -733,7 +733,7 @@ Java_sun_nio_ch_Net_pollConnect(JNIEnv* env, jclass this, jobject fdo, jlong tim
NET_ThrowNew(env, lastError, "getsockopt");
}
} else if (optError != NO_ERROR) {
NET_ThrowNew(env, optError, "getsockopt");
NET_ThrowNew(env, optError, NULL);
}
return JNI_FALSE;
}