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

Better Error Handling for Jar Tool When Processing Non-existent Files

XMLWordPrintable

    • jar
    • b05

        When the jar tool is launched either to create (-c) or to update (-u) a jar file, it gets passed a list of files to include/update the jar file with. One way to pass those options is literally as part of the command. The other way is to include those file paths in a separate file and pass those files to the jar tool as the @that-other-file. The issue here affects both those variants.

        The internal implementation of the jar tool in sun/tools/jar/Main.java, uses a flag called ok to keep track of whether there was any error during the jar tool action processing. This ok flag is marked by various methods that get invoked during the jar processing.

        When -c or -u options are passed to the jar tool, the sun/tools/jar/Main.java calls an internal method expand(). This method is responsible for finalizing the files that need to be included in the jar that gets created or updated. This expand method is also responsible for marking that ok flag if there are any errors (like any file that was specified to be included/updated in the jar, is missing). Once the expand() method returns, the internal implementation detail of the jar tool will go ahead and create a temporary file. Content will be written out to this temporary file The more entries to create in the final jar being created/updated, the more time and disk space this temporary file will consume. Finally, when writing out to the temporary file is done, the ok flag is checked to see if it was flagged as failed. If ok says no errors were noticed, then the temporary file that was created will be moved as the final jar that had to be created/updated. If ok said that there were failures, then the temporary file is deleted and the final jar won't get created (rightly so) nor will the final jar get updated, in case of -u option (rightly so).

        The issue here is that if the expand() method noticed that there was an error with the provided file paths, then it marks the ok flag to indicate that, but the current implementation of the jar tool just doesn't check the flag and goes on to do the expensive work of creating a temporary file and that temporary file will then finally get discarded at the end. This entire process of creating the temporary file can be avoided by checking the ok flag after the expand() method returns. This will improve the whole process of creating a jar file when some of the files are missing.

              wxiao Weibing Xiao
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: