langtools/test/tools/javac/T6725036.java
author chegar
Wed, 03 Dec 2014 19:28:40 +0000
changeset 27858 443efec4bf09
parent 27579 d1a63c99cdd5
parent 27852 2e6ad0e4fe20
child 30730 d3ce7619db2c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     1
/*
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     4
 *
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     8
 *
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    13
 * accompanied this code).
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    14
 *
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1205
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1205
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1205
diff changeset
    21
 * questions.
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    22
 */
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    23
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    24
/*
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    25
 * @test
26527
e422a50bf4f9 8055996: Remove @ignore from tools/javac/T6725036.java
sogoel
parents: 22448
diff changeset
    26
 * @bug 6725036 8016760
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    27
 * @summary javac returns incorrect value for lastModifiedTime() when
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    28
 *          source is a zip file archive
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    29
 * @library /tools/lib
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    30
 * @build ToolBox
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    31
 * @run main T6725036
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    32
 */
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    33
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    34
import java.io.File;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    35
import java.io.IOException;
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    36
import java.util.Date;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    37
import java.util.jar.JarEntry;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    38
import java.util.jar.JarFile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    39
import javax.tools.*;
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    40
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    41
import com.sun.tools.javac.file.JavacFileManager;
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 865
diff changeset
    42
import com.sun.tools.javac.file.RelativePath.RelativeFile;
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    43
import com.sun.tools.javac.file.ZipFileIndex;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    44
import com.sun.tools.javac.file.ZipFileIndexArchive;
8223
638daa596494 6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents: 5520
diff changeset
    45
import com.sun.tools.javac.file.ZipFileIndexCache;
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    46
import com.sun.tools.javac.util.Context;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    47
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    48
public class T6725036 {
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    49
    public static void main(String... args) throws Exception {
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    50
        new T6725036().run();
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    51
    }
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    52
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    53
    void run() throws Exception {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 865
diff changeset
    54
        RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    55
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    56
        File testJar = createJar("test.jar", "java.lang.*");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    57
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    58
        try (JarFile j = new JarFile(testJar)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    59
            JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    60
            long jarEntryTime = je.getTime();
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    61
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    62
            ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance();
27858
chegar
parents: 27579 27852
diff changeset
    63
            ZipFileIndex zfi = zfic.getZipFileIndex(testJar.toPath(), null, false, null, false);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    64
            long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME);
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    65
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    66
            check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime);
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    67
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    68
            Context context = new Context();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    69
            JavacFileManager fm = new JavacFileManager(context, false, null);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    70
            ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    71
            JavaFileObject jfo =
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    72
                zfia.getFileObject(TEST_ENTRY_NAME.dirname(),
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    73
                                       TEST_ENTRY_NAME.basename());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    74
            long jfoTime = jfo.getLastModified();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    75
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    76
            check(je, jarEntryTime, jfo, jfoTime);
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    77
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    78
            if (errors > 0)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    79
                throw new Exception(errors + " occurred");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    80
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    81
    }
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    82
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    83
    File createJar(String name, String... paths) throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    84
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    85
        try (JavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    86
            File f = new File(name);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    87
            ToolBox tb = new ToolBox();
27858
chegar
parents: 27579 27852
diff changeset
    88
            tb.new JarTask(name)
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    89
                .files(fm, StandardLocation.PLATFORM_CLASS_PATH, paths)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    90
                .run();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    91
            return f;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    92
        }
865
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    93
    }
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    94
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    95
    void check(Object ref, long refTime, Object test, long testTime) {
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    96
        if (refTime == testTime)
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    97
            return;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    98
        System.err.println("Error: ");
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
    99
        System.err.println("Expected: " + getText(ref, refTime));
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   100
        System.err.println("   Found: " + getText(test, testTime));
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   101
        errors++;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   102
    }
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   103
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   104
    String getText(Object x, long t) {
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   105
        return String.format("%14d", t) + " (" + new Date(t) + ") from " + x;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   106
    }
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   107
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   108
    int errors;
21668f049d28 6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff changeset
   109
}