Hi,
the attached patch stops the lazy initialization of a Calendar object in
ZipEntry and instead uses a static final one. It also modifies the clone
method to instead of using Object.clone to use the ZipEntry's own copy
constructor. This patch has implications to bootstrapping and subtly
changes ZipEntry's behavior. I welcome feedback prior to committing.
Thanks,
Ian
--- java/util/zip/ZipEntry.java 2007-10-07 19:48:46.000000000 +0100
+++ java/util/zip/ZipEntry.java 2008-02-05 12:32:22.000000000 +0000
@@ -56,9 +56,10 @@
private static final int KNOWN_TIME = 8;
private static final int KNOWN_EXTRA = 16;
- private static Calendar cal;
+ /** Calendar used for time computations */
+ private static final Calendar cal = Calendar.getInstance();
- private String name;
+ private final String name;
private int size;
private long compressedSize = -1;
private int crc;
@@ -140,18 +141,13 @@
*/
public Object clone()
{
- try
- {
- // The JCL says that the `extra' field is also copied.
- ZipEntry clone = (ZipEntry) super.clone();
- if (extra != null)
- clone.extra = (byte[]) extra.clone();
- return clone;
- }
- catch (CloneNotSupportedException ex)
+ ZipEntry clone = new ZipEntry(this);
+ if (extra != null)
{
- throw new InternalError();
+ clone.extra = new byte[extra.length];
+ System.arraycopy(extra, 0, clone.extra, 0, extra.length);
}
+ return clone;
}
/**
@@ -169,7 +165,6 @@
*/
public void setTime(long time)
{
- Calendar cal = getCalendar();
synchronized (cal)
{
cal.setTimeInMillis(time);
@@ -204,7 +199,6 @@
try
{
- cal = getCalendar();
synchronized (cal)
{
cal.set(year, mon, day, hrs, min, sec);
@@ -219,14 +213,6 @@
}
}
- private static synchronized Calendar getCalendar()
- {
- if (cal == null)
- cal = Calendar.getInstance();
-
- return cal;
- }
-
/**
* Sets the size of the uncompressed data.
* @exception IllegalArgumentException if size is not in 0..0xffffffffL