< prev index next >

src/java.base/unix/native/libjava/UnixFileSystem_md.c

Print this page
rev 52387 : 8211752: JNU_ThrowIOExceptionWithLastErrorAndPath - enhance some IOExceptions with path causing the issue

*** 86,95 **** --- 86,104 ---- if (!fileClass) return; ids.path = (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;"); } + static jboolean extendExceptionsWithPath = JNI_FALSE; + + JNIEXPORT void JNICALL + Java_java_io_UnixFileSystem_initIncludeInExceptions(JNIEnv *env, jclass cls, jboolean b) + { + extendExceptionsWithPath = b; + } + + /* -- Path operations -- */ extern int canonicalize(char *path, const char *out, int len); JNIEXPORT jstring JNICALL
*** 100,110 **** --- 109,123 ---- WITH_PLATFORM_STRING(env, pathname, path) { char canonicalPath[PATH_MAX]; if (canonicalize((char *)path, canonicalPath, PATH_MAX) < 0) { + if (extendExceptionsWithPath) { + JNU_ThrowByNameWithTwoMessagesAndLastError(env, "java/io/IOException", "Bad pathname", (char*) path); + } else { JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); + } } else { #ifdef MACOSX rv = newStringPlatform(env, canonicalPath); #else rv = JNU_NewStringPlatform(env, canonicalPath);
*** 276,290 **** FD fd; /* The root directory always exists */ if (strcmp (path, "/")) { fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666); if (fd < 0) { ! if (errno != EEXIST) JNU_ThrowIOExceptionWithLastError(env, path); } else { - if (close(fd) == -1) JNU_ThrowIOExceptionWithLastError(env, path); rv = JNI_TRUE; } } } END_PLATFORM_STRING(env, path); return rv; --- 289,313 ---- FD fd; /* The root directory always exists */ if (strcmp (path, "/")) { fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666); if (fd < 0) { ! if (errno != EEXIST) { ! if (extendExceptionsWithPath) { ! JNU_ThrowByNameWithTwoMessagesAndLastError(env, "java/io/IOException", "handleOpen failed", path); ! } else { JNU_ThrowIOExceptionWithLastError(env, path); + } + } + } else { + if (close(fd) == -1) { + if (extendExceptionsWithPath) { + JNU_ThrowByNameWithTwoMessagesAndLastError(env, "java/io/IOException", "close failed", path); } else { JNU_ThrowIOExceptionWithLastError(env, path); + } + } rv = JNI_TRUE; } } } END_PLATFORM_STRING(env, path); return rv;
< prev index next >