JDK-8318971 : Better Error Handling for Jar Tool When Processing Non-existent Files
  • Type: Bug
  • Component: tools
  • Sub-Component: jar
  • Affected Version: 11,17,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-10-27
  • Updated: 2024-04-22
  • Resolved: 2024-01-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 21 JDK 22 JDK 23
11.0.23-oracleFixed 17.0.11-oracleFixed 21.0.3-oracleFixed 22Fixed 23 b05Fixed
Related Reports
Relates :  
Sub Tasks
JDK-8323314 :  
Description
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.
Comments
Fix request [11u] I backport this for parity with 11.0.23-oracle. Low risk. Simple change, limited to jartool. Clean backport. Adapted """ strings, marked clean. Test passes. SAP nighlty testing passed.
26-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2484 Date: 2024-01-24 13:05:07 +0000
24-01-2024

Fix request [17u,21u] I backport this for parity with 17.0.11-oracle,21.0.3-oracle. Low risk. Simple change, limited to jartool. Clean backport. Test passes. SAP nightly testing passed.
17-01-2024

You are right. Fixed.
17-01-2024

> No risk, only a test change. This doesn't seem quite accurate. There are product code changes performing some error checking. This is fine, though.
15-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/2122 Date: 2024-01-12 13:28:57 +0000
12-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/163 Date: 2024-01-12 13:24:02 +0000
12-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk22/pull/56 Date: 2024-01-10 17:42:21 +0000
10-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk22/pull/55 Date: 2024-01-10 17:02:03 +0000
10-01-2024

Changeset: 8ae309eb Author: Weibing Xiao <weibing.xiao@oracle.com> Committer: Jaikiran Pai <jpai@openjdk.org> Date: 2024-01-09 04:04:12 +0000 URL: https://git.openjdk.org/jdk/commit/8ae309ebacd6947bbad2ef168ca13702e1cba099
09-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17088 Date: 2023-12-13 18:16:56 +0000
13-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16423 Date: 2023-10-30 16:16:52 +0000
21-11-2023