First off, this is my first time contributing a patch :) So please go easy on me if I did something wrong.
This patch is for the jar taskdef. Reading through the JAR file Specification, it implies that the MANIFEST.MF file is to be stored in UTF-8. Looking through the source code for Jar.java and Manifest.java, the MANIFEST.MF file's encoding is dependent on the OS. If one searches in java.sun.com for the bug id: 4260472. Shows that java.util.jar.Manifest attempts to read this file in ASCII. An is currently being fixed (not done yet). Attempting Jar with the source of the manifest file in UTF-8 and exceeds 72 bytes line limit, would result in the following: java.lang.StringIndexOutOfBoundsException: String index out of range: 70 at java.lang.String.substring(String.java:1473) at org.apache.tools.ant.taskdefs.Manifest$Attribute.writeValue(Manifest.java:347) . . This because the number of bytes in UTF-8 to represent a character is 1 to 6 bytes. and the ANT Manifest.java assumes a single byte per character. Below is a fix for this problem which affects 2 files, Jar.java and Manifest.java. I have made the assumption that since the MANIFEST.MF file has to be in UTF-8, the source is in UTF-8 as well. Regards, Noel Index: Jar.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v retrieving revision 1.58 diff -u -r1.58 Jar.java --- Jar.java 9 Dec 2002 12:40:38 -0000 1.58 +++ Jar.java 28 Dec 2002 04:37:49 -0000 @@ -191,7 +191,8 @@ Manifest newManifest = null; Reader r = null; try { - r = new FileReader(manifestFile); + r = new InputStreamReader(new java.io.FileInputStream(manifestFile), + "UTF-8"); newManifest = getManifest(r); } catch (IOException e) { throw new BuildException("Unable to read manifest file: " @@ -317,7 +318,8 @@ zipDir(null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE); // time to write the manifest ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintWriter writer = new PrintWriter(baos); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, + "UTF-8")); manifest.write(writer); writer.flush(); @@ -428,7 +430,11 @@ // is the manifest to use log("Found manifest " + file, Project.MSG_VERBOSE); if (is != null) { - manifest = getManifest(new InputStreamReader(is)); + try { + manifest = getManifest(new InputStreamReader(is, "UTF-8")); + } catch (java.io.UnsupportedEncodingException e) { + manifest = getManifest(new InputStreamReader(is)); + } } else { manifest = getManifest(file); } @@ -441,7 +447,11 @@ try { Manifest newManifest = null; if (is != null) { - newManifest = getManifest(new InputStreamReader(is)); + try { + newManifest = getManifest(new InputStreamReader(is, "UTF-8")); + } catch (java.io.UnsupportedEncodingException e) { + newManifest = getManifest(new InputStreamReader(is)); + } } else { newManifest = getManifest(file); } @@ -498,7 +508,8 @@ } Manifest currentManifest = new Manifest(new InputStreamReader(theZipFile - .getInputStream(entry))); + .getInputStream(entry), + "UTF-8")); Manifest newManifest = createManifest(); if (!currentManifest.equals(newManifest)) { log("Updating jar since jar manifest has changed", Index: Manifest.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java,v retrieving revision 1.37 diff -u -r1.37 Manifest.java --- Manifest.java 4 Oct 2002 12:43:46 -0000 1.37 +++ Manifest.java 28 Dec 2002 04:38:09 -0000 @@ -341,7 +341,8 @@ String line = name + ": " + value; while (line.getBytes().length > MAX_LINE_LENGTH) { // try to find a MAX_LINE_LENGTH byte section - int breakIndex = MAX_SECTION_LENGTH; + int breakIndex = (MAX_SECTION_LENGTH < line.length()) + ? MAX_SECTION_LENGTH : line.length(); String section = line.substring(0, breakIndex); while (section.getBytes().length > MAX_SECTION_LENGTH && breakIndex > 0) { __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>