-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.3.0, 1.4.0, 1.4.2
-
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)
======================================================================
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)
======================================================================
- duplicates
-
JDK-6294255 Manifest is inconsistent when reading/writing
-
- Closed
-
-
JDK-4338265 write() method in class Manifest doesn't write Main Attributes
-
- Closed
-
-
JDK-4490171 Silent errors creating Manifest from stream1.
-
- Closed
-