Details
-
Bug
-
Resolution: Fixed
-
P4
-
8
Description
FileInputStream.java, FileOutputStream.java, and RandomAccessFile.java are all mapping their native open() method to fileOpen function defined in src/windows/native/java/io/io_util_md.c. In the current version, fileOpen function calls winFileHandleOpen function to do the work. But inside the error handling part of winFileHandleOpen function, it can throw out not only FileNotFoundException but also IOException as shown in the following code snippet.
253 if (h == INVALID_HANDLE_VALUE) {
254 int error = GetLastError();
255 if (error == ERROR_TOO_MANY_OPEN_FILES) {
256 JNU_ThrowByName(env, JNU_JAVAIOPKG "IOException",
257 "Too many open files");
258 return -1;
259 }
260 throwFileNotFoundException(env, path);
261 return -1;
262 }
On other platforms, fileOpen function defined in src/solaris/native/java/io/io_util_md.c only throws out FileNotFoundException.
But in the corresponding java parts, all related methods are only defined to "throws FileNotFoundException", which is incorrect given what we have for the Windows platform. Basically, I think these java methods should be defined to "throws IOException" instead of FileNotFoundException unless we change the above error-handling codes on windows.
Here is the list of related java methods,
RandomAccessFile.open(String name, int mode)
RandomAccessFile(String name, String mode)
RandomAccessFile(File file, String mode)
FileOutputStream.open(String name, boolean append)
FileOutputStream(String name)
FileOutputStream(String name, boolean append)
FileOutputStream(File file)
FileOutputStream(File file, boolean append)
FileInputStream.open(String name)
FileInputStream(String name)
FileInputStream(File file)
Other java classes, which use the above methods, might also need to be scanned and changed.
253 if (h == INVALID_HANDLE_VALUE) {
254 int error = GetLastError();
255 if (error == ERROR_TOO_MANY_OPEN_FILES) {
256 JNU_ThrowByName(env, JNU_JAVAIOPKG "IOException",
257 "Too many open files");
258 return -1;
259 }
260 throwFileNotFoundException(env, path);
261 return -1;
262 }
On other platforms, fileOpen function defined in src/solaris/native/java/io/io_util_md.c only throws out FileNotFoundException.
But in the corresponding java parts, all related methods are only defined to "throws FileNotFoundException", which is incorrect given what we have for the Windows platform. Basically, I think these java methods should be defined to "throws IOException" instead of FileNotFoundException unless we change the above error-handling codes on windows.
Here is the list of related java methods,
RandomAccessFile.open(String name, int mode)
RandomAccessFile(String name, String mode)
RandomAccessFile(File file, String mode)
FileOutputStream.open(String name, boolean append)
FileOutputStream(String name)
FileOutputStream(String name, boolean append)
FileOutputStream(File file)
FileOutputStream(File file, boolean append)
FileInputStream.open(String name)
FileInputStream(String name)
FileInputStream(File file)
Other java classes, which use the above methods, might also need to be scanned and changed.