Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8292016: Cleanup legacy error reporting in the JDK outside of HotSpot #9870

Closed
wants to merge 21 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/java.base/aix/native/libnio/ch/AixPollPort.c
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ Java_sun_nio_ch_AixPollPort_pollsetCreate(JNIEnv *env, jclass c) {
* cannot predict this number so we leave it at OPEN_MAX. */
pollset_t ps = _pollset_create(-1);
if (ps < 0) {
JNU_ThrowIOExceptionWithLastError(env, "pollset_create failed");
JNU_ThrowIOExceptionWithIOError(env, "pollset_create failed");
}
return (int)ps;
}
@@ -123,7 +123,7 @@ Java_sun_nio_ch_AixPollPort_pollsetPoll(JNIEnv *env, jclass c,

RESTARTABLE(_pollset_poll(ps, events, numfds, -1), res);
if (res < 0) {
JNU_ThrowIOExceptionWithLastError(env, "pollset_poll failed");
JNU_ThrowIOExceptionWithIOError(env, "pollset_poll failed");
}
return res;
}
@@ -138,7 +138,7 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_AixPollPort_socketpair(JNIEnv* env, jclass clazz, jintArray sv) {
int sp[2];
if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "socketpair failed");
JNU_ThrowIOExceptionWithIOError(env, "socketpair failed");
} else {
jint res[2];
res[0] = (jint)sp[0];
@@ -154,7 +154,7 @@ Java_sun_nio_ch_AixPollPort_interrupt(JNIEnv *env, jclass c, jint fd) {
buf[0] = 1;
RESTARTABLE(write(fd, buf, 1), res);
if (res < 0) {
JNU_ThrowIOExceptionWithLastError(env, "write failed");
JNU_ThrowIOExceptionWithIOError(env, "write failed");
}
}

@@ -164,7 +164,7 @@ Java_sun_nio_ch_AixPollPort_drain1(JNIEnv *env, jclass cl, jint fd) {
char buf[1];
RESTARTABLE(read(fd, buf, 1), res);
if (res < 0) {
JNU_ThrowIOExceptionWithLastError(env, "drain1 failed");
JNU_ThrowIOExceptionWithIOError(env, "drain1 failed");
}
}

4 changes: 2 additions & 2 deletions src/java.base/aix/native/libnio/ch/FileDispatcherImpl.c
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ handle(JNIEnv *env, jlong rv, char *msg)
return rv;
if (errno == EINTR)
return IOS_INTERRUPTED;
JNU_ThrowIOExceptionWithLastError(env, msg);
JNU_ThrowIOExceptionWithIOError(env, msg);
return IOS_THROWN;
}

@@ -118,7 +118,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferTo0(JNIEnv *env, jobject this,
return IOS_INTERRUPTED;
if (errno == ENOTSOCK)
return IOS_UNSUPPORTED;
JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
JNU_ThrowIOExceptionWithIOError(env, "Transfer failed");
return IOS_THROWN;
}

4 changes: 2 additions & 2 deletions src/java.base/linux/native/libnio/ch/EPoll.c
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_EPoll_create(JNIEnv *env, jclass clazz) {
int epfd = epoll_create1(EPOLL_CLOEXEC);
if (epfd < 0) {
JNU_ThrowIOExceptionWithLastError(env, "epoll_create1 failed");
JNU_ThrowIOExceptionWithIOError(env, "epoll_create1 failed");
}
return epfd;
}
@@ -88,7 +88,7 @@ Java_sun_nio_ch_EPoll_wait(JNIEnv *env, jclass clazz, jint epfd,
if (errno == EINTR) {
return IOS_INTERRUPTED;
} else {
JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed");
JNU_ThrowIOExceptionWithIOError(env, "epoll_wait failed");
return IOS_THROWN;
}
}
2 changes: 1 addition & 1 deletion src/java.base/linux/native/libnio/ch/EventFD.c
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ Java_sun_nio_ch_EventFD_eventfd0(JNIEnv *env, jclass klazz)
{
int efd = eventfd((uint64_t)0, 0);
if (efd == -1) {
JNU_ThrowIOExceptionWithLastError(env, "eventfd failed");
JNU_ThrowIOExceptionWithIOError(env, "eventfd failed");
return IOS_THROWN;
}
return efd;
6 changes: 3 additions & 3 deletions src/java.base/linux/native/libnio/ch/FileDispatcherImpl.c
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferFrom0(JNIEnv *env, jobject this,
if (errno == EINTR) {
return IOS_INTERRUPTED;
}
JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
JNU_ThrowIOExceptionWithIOError(env, "Transfer failed");
return IOS_THROWN;
}
return n;
@@ -106,7 +106,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferTo0(JNIEnv *env, jobject this,
// ignore and try sendfile()
break;
default:
JNU_ThrowIOExceptionWithLastError(env, "Copy failed");
JNU_ThrowIOExceptionWithIOError(env, "Copy failed");
return IOS_THROWN;
}
}
@@ -123,7 +123,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferTo0(JNIEnv *env, jobject this,
if (errno == EINTR) {
return IOS_INTERRUPTED;
}
JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
JNU_ThrowIOExceptionWithIOError(env, "Transfer failed");
return IOS_THROWN;
}
return n;
Original file line number Diff line number Diff line change
@@ -202,7 +202,7 @@ Java_sun_nio_fs_LinuxNativeDispatcher_directCopy0
// ignore and try sendfile()
break;
default:
JNU_ThrowIOExceptionWithLastError(env, "Copy failed");
JNU_ThrowIOExceptionWithIOError(env, "Copy failed");
return IOS_THROWN;
}
}
10 changes: 5 additions & 5 deletions src/java.base/macosx/native/libjava/ProcessHandleImpl_macosx.c
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ jint os_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray,
// Get buffer size needed to read all processes
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
if (sysctl(mib, 4, NULL, &bufSize, NULL, 0) < 0) {
JNU_ThrowByNameWithLastError(env,
JNU_ThrowByNameWithStrerror(env,
"java/lang/RuntimeException", "sysctl failed");
return -1;
}
@@ -106,7 +106,7 @@ jint os_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray,

// Read process info for all processes
if (sysctl(mib, 4, buffer, &bufSize, NULL, 0) < 0) {
JNU_ThrowByNameWithLastError(env,
JNU_ThrowByNameWithStrerror(env,
"java/lang/RuntimeException", "sysctl failed");
free(buffer);
return -1;
@@ -189,7 +189,7 @@ pid_t os_getParentPidAndTimings(JNIEnv *env, pid_t jpid,
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};

if (sysctl(mib, 4, &kp, &bufSize, NULL, 0) < 0) {
JNU_ThrowByNameWithLastError(env,
JNU_ThrowByNameWithStrerror(env,
"java/lang/RuntimeException", "sysctl failed");
return -1;
}
@@ -251,7 +251,7 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
mib[1] = KERN_ARGMAX;
size = sizeof(maxargs);
if (sysctl(mib, 2, &maxargs, &size, NULL, 0) == -1) {
JNU_ThrowByNameWithLastError(env,
JNU_ThrowByNameWithStrerror(env,
"java/lang/RuntimeException", "sysctl failed");
return;
}
@@ -274,7 +274,7 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
if (sysctl(mib, 3, args, &size, NULL, 0) == -1) {
if (errno != EINVAL && errno != EIO) {
// If the pid is invalid, the information returned is empty and no exception
JNU_ThrowByNameWithLastError(env,
JNU_ThrowByNameWithStrerror(env,
"java/lang/RuntimeException", "sysctl failed");
}
break;
6 changes: 3 additions & 3 deletions src/java.base/macosx/native/libjli/java_md_macosx.m
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@
main_fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
#endif
if (main_fptr == NULL) {
JLI_ReportErrorMessageSys("error locating main entrypoint\n");
JLI_Perror("error locating main entrypoint");
exit(1);
}
}
@@ -346,11 +346,11 @@ static void MacOSXStartup(int argc, char *argv[]) {
// Fire up the main thread
pthread_t main_thr;
if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
JLI_Perror("Could not create main thread");
exit(1);
}
if (pthread_detach(main_thr)) {
JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
JLI_Perror("pthread_detach() failed");
exit(1);
}

4 changes: 2 additions & 2 deletions src/java.base/macosx/native/libnio/ch/FileDispatcherImpl.c
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ handle(JNIEnv *env, jlong rv, char *msg)
return rv;
if (errno == EINTR)
return IOS_INTERRUPTED;
JNU_ThrowIOExceptionWithLastError(env, msg);
JNU_ThrowIOExceptionWithIOError(env, msg);
return IOS_THROWN;
}

@@ -94,7 +94,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferTo0(JNIEnv *env, jobject this,
return IOS_UNSUPPORTED_CASE;
if (errno == EINTR)
return IOS_INTERRUPTED;
JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
JNU_ThrowIOExceptionWithIOError(env, "Transfer failed");
return IOS_THROWN;
}

4 changes: 2 additions & 2 deletions src/java.base/macosx/native/libnio/ch/KQueue.c
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_KQueue_create(JNIEnv *env, jclass clazz) {
int kqfd = kqueue();
if (kqfd < 0) {
JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");
JNU_ThrowIOExceptionWithIOError(env, "kqueue failed");
return IOS_THROWN;
}
return kqfd;
@@ -105,7 +105,7 @@ Java_sun_nio_ch_KQueue_poll(JNIEnv *env, jclass clazz, jint kqfd, jlong address,
if (errno == EINTR) {
return IOS_INTERRUPTED;
} else {
JNU_ThrowIOExceptionWithLastError(env, "kqueue failed");
JNU_ThrowIOExceptionWithIOError(env, "kqueue failed");
return IOS_THROWN;
}
}
10 changes: 5 additions & 5 deletions src/java.base/share/native/libjava/FileInputStream.c
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ Java_java_io_FileInputStream_length0(JNIEnv *env, jobject this) {
return -1;
}
if ((length = IO_GetLength(fd)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "GetLength failed");
JNU_ThrowIOExceptionWithIOError(env, "GetLength failed");
}
return length;
}
@@ -100,7 +100,7 @@ Java_java_io_FileInputStream_position0(JNIEnv *env, jobject this) {
return -1;
}
if ((ret = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
JNU_ThrowIOExceptionWithIOError(env, "Seek failed");
}
return ret;
}
@@ -115,9 +115,9 @@ Java_java_io_FileInputStream_skip0(JNIEnv *env, jobject this, jlong toSkip) {
return 0;
}
if ((cur = IO_Lseek(fd, (jlong)0, (jint)SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek error");
JNU_ThrowIOExceptionWithIOError(env, "Seek error");
} else if ((end = IO_Lseek(fd, toSkip, (jint)SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek error");
JNU_ThrowIOExceptionWithIOError(env, "Seek error");
}
return (end - cur);
}
@@ -138,6 +138,6 @@ Java_java_io_FileInputStream_available0(JNIEnv *env, jobject this) {
}
return jlong_to_jint(ret);
}
JNU_ThrowIOExceptionWithLastError(env, NULL);
JNU_ThrowIOExceptionWithIOError(env, NULL);
return 0;
}
8 changes: 4 additions & 4 deletions src/java.base/share/native/libjava/RandomAccessFile.c
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ Java_java_io_RandomAccessFile_getFilePointer(JNIEnv *env, jobject this) {
return -1;
}
if ((ret = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
JNU_ThrowIOExceptionWithIOError(env, "Seek failed");
}
return ret;
}
@@ -117,7 +117,7 @@ Java_java_io_RandomAccessFile_length0(JNIEnv *env, jobject this) {
return -1;
}
if ((length = IO_GetLength(fd)) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "GetLength failed");
JNU_ThrowIOExceptionWithIOError(env, "GetLength failed");
}
return length;
}
@@ -136,7 +136,7 @@ Java_java_io_RandomAccessFile_seek0(JNIEnv *env,
if (pos < jlong_zero) {
JNU_ThrowIOException(env, "Negative seek offset");
} else if (IO_Lseek(fd, pos, SEEK_SET) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
JNU_ThrowIOExceptionWithIOError(env, "Seek failed");
}
}

@@ -162,5 +162,5 @@ Java_java_io_RandomAccessFile_setLength0(JNIEnv *env, jobject this,
return;

fail:
JNU_ThrowIOExceptionWithLastError(env, "setLength failed");
JNU_ThrowIOExceptionWithIOError(env, "setLength failed");
}
21 changes: 14 additions & 7 deletions src/java.base/share/native/libjava/io_util.c
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) {
if (nread == 0) { /* EOF */
return -1;
} else if (nread == -1) { /* error */
JNU_ThrowIOExceptionWithLastError(env, "Read error");
JNU_ThrowIOExceptionWithIOError(env, "Read error");
}
return ret & 0xFF;
}
@@ -110,7 +110,7 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
if (nread > 0) {
(*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf);
} else if (nread == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Read error");
JNU_ThrowIOExceptionWithIOError(env, "Read error");
} else { /* EOF */
nread = -1;
}
@@ -138,7 +138,7 @@ writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid)
n = IO_Write(fd, &c, 1);
}
if (n == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Write error");
JNU_ThrowIOExceptionWithIOError(env, "Write error");
}
}

@@ -189,7 +189,7 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
n = IO_Write(fd, buf+off, len);
}
if (n == -1) {
JNU_ThrowIOExceptionWithLastError(env, "Write error");
JNU_ThrowIOExceptionWithIOError(env, "Write error");
break;
}
off += n;
@@ -204,13 +204,20 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
void
throwFileNotFoundException(JNIEnv *env, jstring path)
{
char buf[256];
size_t n;
jobject x;
jstring why = NULL;

n = getLastErrorString(buf, sizeof(buf));
#ifdef _WIN32
/* The implementation on Windows uses the Windows API */
char buf[256];
size_t n = getLastWinErrorString(buf, sizeof(buf));
if (n > 0) {
#else
char* buf = NULL;
const int error = errno;
if (error != 0) buf = strerror(error);
if (buf != NULL) {
#endif
why = JNU_NewStringPlatform(env, buf);
CHECK_NULL(why);
}
Loading