Warnings Cleanup in java.util. (more from hack day) (original) (raw)

Michael Barker mikeb01 at gmail.com
Fri Dec 2 11:24:29 PST 2011


Hi,

We had some late submissions from our hack day participants. 2 more patches. One (j.u.z.ZipEntry) is possibly a little more involved for a warnings fix. It removes a usage of deprecated Date APIs in favour of Calendar. However, the fix results in code that is very similar to Apache Harmony implementation. The other is a couple of fixes for generics (j.u.j.Manifest).

Thanks to:

Regards, Michael Barker mikeb2701 -------------- next part -------------- diff -r 43a630f11af6 src/share/classes/java/util/jar/Manifest.java --- a/src/share/classes/java/util/jar/Manifest.java Wed Nov 30 13:11:16 2011 -0800 +++ b/src/share/classes/java/util/jar/Manifest.java Fri Dec 02 19:15:58 2011 +0000 @@ -30,6 +30,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.HashMap; import java.util.Iterator; @@ -51,7 +52,7 @@ private Attributes attr = new Attributes(); // manifest entries - private Map entries = new HashMap(); + private Map<String, Attributes> entries = new HashMap<>(); /** * Constructs a new, empty Manifest. @@ -148,20 +149,20 @@ // Write out the main attributes for the manifest attr.writeMain(dos); // Now write out the pre-entry attributes - Iterator it = entries.entrySet().iterator(); + Iterator<Map.Entry<String, Attributes>> it = entries.entrySet().iterator(); while (it.hasNext()) { - Map.Entry e = (Map.Entry)it.next(); + Map.Entry<String, Attributes> e = it.next(); StringBuffer buffer = new StringBuffer("Name: "); - String value = (String)e.getKey(); + String value = e.getKey(); if (value != null) { - byte[] vb = value.getBytes("UTF8"); - value = new String(vb, 0, 0, vb.length); + byte[] vb = value.getBytes(StandardCharsets.UTF_8); + value = new String(vb, 0, 0, StandardCharsets.UTF_8); } buffer.append(value); buffer.append("\r\n"); make72Safe(buffer); dos.writeBytes(buffer.toString()); - ((Attributes)e.getValue()).write(dos); + e.getValue().write(dos); } dos.flush(); } -------------- next part -------------- diff -r 43a630f11af6 src/share/classes/java/util/zip/ZipEntry.java --- a/src/share/classes/java/util/zip/ZipEntry.java Wed Nov 30 13:11:16 2011 -0800 +++ b/src/share/classes/java/util/zip/ZipEntry.java Fri Dec 02 19:12:54 2011 +0000 @@ -24,7 +24,7 @@ */ package java.util.zip;

+import java.util.Calendar; import java.util.Date;

/** @@ -281,27 +281,33 @@ * Converts DOS time to Java time (number of milliseconds since epoch). */ private static long dosToJavaTime(long dtime) {



More information about the jdk8-dev mailing list