Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8021977

Opening a file using java.io can throw IOException on Windows

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b105
    • OS:
      windows
    • Verification:
      Not verified

      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.

        Attachments

          Activity

            People

            • Assignee:
              dxu Dan Xu (Inactive)
              Reporter:
              dxu Dan Xu (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: