8073187: Unexpected side effect in Pack200
authorksrini
Tue, 22 Sep 2015 11:50:40 -0700
changeset 32850 59bcc3c351e6
parent 32849 a2a6b6d26059
child 32851 c88a02770d60
8073187: Unexpected side effect in Pack200 Reviewed-by: jrose, sherman
jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PropMap.java
jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/Utils.java
jdk/test/tools/pack200/Pack200Props.java
--- a/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java	Thu Oct 01 09:59:16 2015 -0400
+++ b/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java	Tue Sep 22 11:50:40 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.time.ZoneOffset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -41,7 +42,6 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.SortedMap;
-import java.util.TimeZone;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
@@ -84,13 +84,8 @@
      */
     public synchronized void pack(JarFile in, OutputStream out) throws IOException {
         assert(Utils.currentInstance.get() == null);
-        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
-                      ? null
-                      : TimeZone.getDefault();
         try {
             Utils.currentInstance.set(this);
-            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
-
             if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
                 Utils.copyJarFile(in, out);
             } else {
@@ -98,7 +93,6 @@
             }
         } finally {
             Utils.currentInstance.set(null);
-            if (tz != null) TimeZone.setDefault(tz);
             in.close();
         }
     }
@@ -119,11 +113,8 @@
      */
     public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
         assert(Utils.currentInstance.get() == null);
-        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)) ? null :
-            TimeZone.getDefault();
         try {
             Utils.currentInstance.set(this);
-            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
             if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
                 Utils.copyJarFile(in, out);
             } else {
@@ -131,7 +122,6 @@
             }
         } finally {
             Utils.currentInstance.set(null);
-            if (tz != null) TimeZone.setDefault(tz);
             in.close();
         }
     }
@@ -327,7 +317,9 @@
                 this.f = null;
                 this.jf = jf;
                 this.je = je;
-                int timeSecs = getModtime(je.getTime());
+                int timeSecs = (int) je.getTimeLocal()
+                        .atOffset(ZoneOffset.UTC)
+                        .toEpochSecond();
                 if (keepModtime && timeSecs != Constants.NO_MODTIME) {
                      this.modtime = timeSecs;
                 } else if (latestModtime && timeSecs > pkg.default_modtime) {
--- a/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PropMap.java	Thu Oct 01 09:59:16 2015 -0400
+++ b/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/PropMap.java	Tue Sep 22 11:50:40 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -69,10 +69,6 @@
         props.put(Utils.DEBUG_VERBOSE,
                   String.valueOf(Integer.getInteger(Utils.DEBUG_VERBOSE,0)));
 
-        // Set the PACK_TIMEZONE_NO_UTC
-        props.put(Utils.PACK_DEFAULT_TIMEZONE,
-                  String.valueOf(Boolean.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)));
-
         // The segment size is unlimited
         props.put(Pack200.Packer.SEGMENT_LIMIT, "-1");
 
--- a/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java	Thu Oct 01 09:59:16 2015 -0400
+++ b/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java	Tue Sep 22 11:50:40 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,10 +32,11 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.SortedMap;
-import java.util.TimeZone;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
@@ -95,13 +96,9 @@
             throw new NullPointerException("null output");
         }
         assert(Utils.currentInstance.get() == null);
-        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
-                      ? null
-                      : TimeZone.getDefault();
 
         try {
             Utils.currentInstance.set(this);
-            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
             final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
             BufferedInputStream in0 = new BufferedInputStream(in);
             if (Utils.isJarMagic(Utils.readMagic(in0))) {
@@ -125,7 +122,6 @@
         } finally {
             _nunp = null;
             Utils.currentInstance.set(null);
-            if (tz != null) TimeZone.setDefault(tz);
         }
     }
 
@@ -246,9 +242,9 @@
                     je.setCrc(crc.getValue());
                 }
                 if (keepModtime) {
-                    je.setTime(file.modtime);
-                    // Convert back to milliseconds
-                    je.setTime((long)file.modtime * 1000);
+                    LocalDateTime ldt = LocalDateTime
+                            .ofEpochSecond(file.modtime, 0, ZoneOffset.UTC);
+                    je.setTimeLocal(ldt);
                 } else {
                     je.setTime((long)modtime * 1000);
                 }
--- a/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/Utils.java	Thu Oct 01 09:59:16 2015 -0400
+++ b/jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/Utils.java	Tue Sep 22 11:50:40 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,13 +62,6 @@
     static final String DEBUG_DISABLE_NATIVE = COM_PREFIX+"disable.native";
 
     /*
-     * Use the default working TimeZone instead of UTC.
-     * Note: This has installer unpacker implications.
-     * see: zip.cpp which uses gmtime vs. localtime.
-     */
-    static final String PACK_DEFAULT_TIMEZONE = COM_PREFIX+"default.timezone";
-
-    /*
      * Property indicating that the unpacker should
      * ignore the transmitted PACK_MODIFICATION_TIME,
      * replacing it by the given value. The value can
--- a/jdk/test/tools/pack200/Pack200Props.java	Thu Oct 01 09:59:16 2015 -0400
+++ b/jdk/test/tools/pack200/Pack200Props.java	Tue Sep 22 11:50:40 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -88,8 +88,6 @@
     private static void verifyDefaults() {
         Map<String, String> expectedDefaults = new HashMap<>();
         Packer p = Pack200.newPacker();
-        expectedDefaults.put("com.sun.java.util.jar.pack.default.timezone",
-                p.FALSE);
         expectedDefaults.put("com.sun.java.util.jar.pack.disable.native",
                 p.FALSE);
         expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");