Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2465

TestHelper.generateTempFileFromResource file handling is invalid on windows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.4.8
    • 3.5.0, 3.4.9
    • test-suite
    • None
    • Windows

    Description

      In org.apache.tinkerpop.gremlin.TestHelper there's a method "generateTempFileFromResource":

      public static File generateTempFileFromResource(final Class graphClass, final Class resourceClass, final String resourceName, final String extension, final boolean overwrite) throws IOException {
          final File temp = makeTestDataPath(graphClass, "resources");
          if (!temp.exists()) temp.mkdirs();
          final File tempFile = new File(temp, resourceName + extension);
          if (!tempFile.exists() || overwrite) {
              try (final FileOutputStream outputStream = new FileOutputStream(tempFile)) {
                  int data;
                  try (final InputStream inputStream = resourceClass.getResourceAsStream(resourceName)) {
                      while ((data = inputStream.read()) != -1) {
                          outputStream.write(data);
                      }
                  }
              }
          }
          return tempFile;
      }
      

      The problem with this method is this section:

       if (!tempFile.exists() || overwrite) { try (final FileOutputStream outputStream = new FileOutputStream(tempFile)) {
      

      If the temp file does not exist, a new FileOutputStream is created. However, the way the file system reacts to a file output stream being created on a non-existing file is not the same across all file systems. In particular on windows, the file system will throw an error in this case, indicating that the file does not exist.

       

      This effectively breaks the gremlin test suite when it's running on windows.

       

      The fix would be to first create the file, then opening the file output stream on it.

       

      Attachments

        Activity

          People

            spmallette Stephen Mallette
            martin.haeusler Martin Häusler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: