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

Multiline values not properly supported when writing manifests

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      According to https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#name-value-pairs-and-sections empty new line always indicate a new section.

      But still arbitrary header values should be allowed (even those containing empty lines). The empty lines are not properly escaped though (i.e. the leading space is missing) when using the regular Manifest.write(...) method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just execute the attached source code to see the problem.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A valid manifest:
      "
      Manifest-Version: 1.0
      Test: Some paragraph
       
       Another paragraph
      "
      ACTUAL -
      An invalid manifest:
      "
      Manifest-Version: 1.0
      Test: Some paragraph

      Another paragraph
      "

      ---------- BEGIN SOURCE ----------

      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.util.jar.Attributes;
      import java.util.jar.Manifest;

      public class ManifestTestWithEmptyLinesInAttributeValues {

          public static void main(String[] args) throws IOException {
              File tempFile = File.createTempFile("manifest", null);
              try {
                  Manifest manifest = new Manifest();
                  Attributes attributes = manifest.getMainAttributes();
                  attributes.putValue("Test", "Some paragraph\n\nAnother paragraph");
                  attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
                  try (FileOutputStream outputStream = new FileOutputStream(tempFile)) {
                      manifest.write(outputStream);
                  };
                  try (FileInputStream inputStream = new FileInputStream(tempFile)) {
                      manifest = new Manifest(inputStream);
                  }
              } finally {
                  tempFile.delete();
              }
          }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: