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

Manifest.write(OutputStream) does not write main attrs when no Manifest-Version

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.3.0, 1.4.0, 1.4.2
    • core-libs
    • Fix Understood
    • generic, other
    • generic, windows_nt

      Name: rlT66838 Date: 09/13/99




      java.util.jar.Manifest correctly writes out main attributes for
      a manifest only if there is a Manifest-Version or Signature-Version
      tag present in the main attributes. This problem seems to have
      been introduced in 1.2 by the fix for #4120655.

      Although the Manifest spec does say that this attr is required,
      it seems unfriendly to just fail this way--skipping the main
      section completely, and thus making an invalid manifest on the
      output. Suggested alternate behaviors:

      1. Just write out the main section without Manifest-Version,
      though this is not a valid main section.

      2. Automatically insert "Manifest-Version: 1.0" (if no manifest
      version was explicitly present in the main attrs).

      3. Fail with an IOException notifying the caller that an attempt
      was made to write an invalid manifest.

      Details:

      1. To reproduce, run following source code.

      2. Source code:
      --------------%<-------------
      import java.util.jar.*;
      import java.io.*;
      public class ManifestTest {
        public static void main (String args[]) throws IOException {
          Manifest m = new Manifest ();
          show (m);
          m.read (new StringBufferInputStream ("Foo: fooval\nBar: barval\n\nName: section.class\nAttr1: attr1val\nAttr2: attr2val\n"));
          show (m);
          m.getMainAttributes ().putValue ("Foo", "fooval (2)");
          m.getMainAttributes ().putValue ("Baz", "bazval (2)");
          m.getAttributes ("section.class").putValue ("Attr1", "attr1val (2)");
          m.getAttributes ("section.class").putValue ("Attr3", "attr3val (new)");
          Attributes a = new Attributes ();
          a.putValue ("NewAttr", "new value");
          m.getEntries ().put ("new-section.txt", a);
          show (m);
          m.getMainAttributes ().put (Attributes.Name.MANIFEST_VERSION, "1.0");
          show (m);
        }
        private static void show (Manifest m) throws IOException {
          System.err.println (">>>>>>>>>>>>>>>>>>>>");
          m.write (System.err);
          System.err.println ("<<<<<<<<<<<<<<<<<<<<");
        }
      }
      -----------------%<--------------

      3. Output:

      -----------------<%--------------
      >>>>>>>>>>>>>>>>>>>>

      <<<<<<<<<<<<<<<<<<<<
      >>>>>>>>>>>>>>>>>>>>

      Name: section.class
      Attr2: attr2val
      Attr1: attr1val

      <<<<<<<<<<<<<<<<<<<<
      >>>>>>>>>>>>>>>>>>>>

      Name: new-section.txt
      NewAttr: new value

      Name: section.class
      Attr3: attr3val (new)
      Attr2: attr2val
      Attr1: attr1val (2)

      <<<<<<<<<<<<<<<<<<<<
      >>>>>>>>>>>>>>>>>>>>
      Manifest-Version: 1.0
      Bar: barval
      Baz: bazval (2)
      Foo: fooval (2)

      Name: new-section.txt
      NewAttr: new value

      Name: section.class
      Attr3: attr3val (new)
      Attr2: attr2val
      Attr1: attr1val (2)

      <<<<<<<<<<<<<<<<<<<<
      ----------------%<------------

      4. N/A

      5. java -version:
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
         java -fullversion:
      java full version "1.3beta-O"

      6. N/A
      (Review ID: 95173)
      ======================================================================

            Unassigned Unassigned
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: