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

Attributes::writeMain ignores other attributes if there is no MANIFEST_VERSION or SIGNATURE_VERSION

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      src/java.base/share/classes/java/util/jar/Attributes.java:

        329 @SuppressWarnings("deprecation")
        330 void writeMain(DataOutputStream out) throws IOException
        331 {
        332 // write out the *-Version header first, if it exists
        333 String vername = Name.MANIFEST_VERSION.toString();
        334 String version = getValue(vername);
        335 if (version == null) {
        336 vername = Name.SIGNATURE_VERSION.toString();
        337 version = getValue(vername);
        338 }
        339
        340 if (version != null) {
        341 out.writeBytes(vername+": "+version+"\r\n");
        342 }
        343
        344 // write out all attributes except for the version
        345 // we wrote out earlier
        346 for (Entry<Object, Object> e : entrySet()) {
        347 String name = ((Name) e.getKey()).toString();
        348 if ((version != null) && !(name.equalsIgnoreCase(vername))) {
            .... (write this entry)

      So, if there is no existing MANIFEST_VERSION or SIGNATURE_VERSION, then version is null and the check above will be false for ever and any other attribute cannot be written out.

      If this is intended, then there is no need to iterate through all entries and the method can just return after line 338. Otherwise, the version != null check should be removed so the other entries can be written out.

      I tend to believe the latter is correct. I cannot find a place saying a MANIFEST_VERSION or SIGNATURE_VERSION must be provided. Even if so, this should be an error and it's not a good idea to silently drop all other attributes.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                weijun Weijun Wang
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: