-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.4.2
-
Cause Known
-
sparc
-
solaris_8
Name: rmT116609 Date: 10/09/2003
A DESCRIPTION OF THE REQUEST :
It looks like the Attributes.writeMain method requires either the Name.MANIFEST_VERSION or the Name.SIGNATURE_VERSION to be defined. If neither of these attributes are defined none of the other attributes defined will be written to the Manifest file. One of these attributes may be required by the spec (I'm not sure).
Either way this behavior is very confusing to users. A user can create a new Manifest and add a large set of attributes to the Manifest's attribute list. If they do not add a Name.MANIFEST_VERSION or a Name.SIGNATURE_VERSION attribute none of the user added attributes will be written to the manifest file. The user ends up with an empty manifest which is a bit confusing. If one of these two attributes is required shouldn't the default c'tor for the Manifest class add one of these attributes. If this is undesireable then the writeMain method should probably throw an exception if it does not find one of these required attributes.
Code in question from java.util.jar.Attributes:
If version is null no other attributes will be written to the StringBuffer (and eventually will not be added to the output stream and written to the manifest file).
void writeMain(DataOutputStream out) throws IOException
{
// write out the *-Version header first, if it exists
String vername = Name.MANIFEST_VERSION.toString();
String version = getValue(vername);
if (version == null) {
vername = Name.SIGNATURE_VERSION.toString();
version = getValue(vername);
}
if (version != null) {
out.writeBytes(vername+": "+version+"\r\n");
}
// write out all attributes except for the version
// we wrote out earlier
Iterator it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
String name = ((Name)e.getKey()).toString();
if ((version != null) && ! (name.equalsIgnoreCase(vername))) {
StringBuffer buffer = new StringBuffer(name);
buffer.append(": ");
String value = (String)e.getValue();
if (value != null) {
byte[] vb = value.getBytes("UTF8");
value = new String(vb, 0, 0, vb.length);
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
out.writeBytes(buffer.toString());
}
}
out.writeBytes("\r\n");
}
JUSTIFICATION :
It is not necessary but would be a nice feature to notify users (or do it for them) they must add either the Name.MANIFEST_VERSION or the Name.SIGNATURE_VERSION to the list of attributes in their newly created Manifest object.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A warning or a manifest file with the defined attributes.
ACTUAL -
an empty manifest file with no warning or error.
---------- BEGIN SOURCE ----------
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.io.*;
public class ManifestIt {
public void go() throws Exception {
Attributes atts = new Attributes();
atts.putValue("name", "value");
atts.putValue("name2", "value2");
//atts.putValue("Manifest-Version", "1.0");
Manifest man = new Manifest();
Attributes existingAtts = man.getMainAttributes();
existingAtts.putAll(atts);
man.write(new FileOutputStream("c:\\temp\\manifest"));
}
public static void main(String[] args) throws Exception {
ManifestIt it = new ManifestIt();
it.go();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Simply add either the Name.MANIFEST_VERSION or the Name.SIGNATURE_VERSION attribute to your Manifest object.
(Incident Review ID: 208053)
======================================================================