Thu, 25 Jul 2013 14:51:40 +0100
8020843: javac crashes on accessibility check with method reference with typevar receiver
Summary: method reference overload check doesn't walk through type-variable receivers
Reviewed-by: jjg
jjg@71 | 1 | /* |
jjg@839 | 2 | * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@71 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@71 | 4 | * |
jjg@71 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@71 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@71 | 7 | * published by the Free Software Foundation. |
jjg@71 | 8 | * |
jjg@71 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@71 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@71 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@71 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@71 | 13 | * accompanied this code). |
jjg@71 | 14 | * |
jjg@71 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@71 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@71 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@71 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@71 | 22 | */ |
jjg@71 | 23 | |
jjg@71 | 24 | /* |
jjg@71 | 25 | * @test |
jjg@71 | 26 | * @bug 6725036 |
emc@1870 | 27 | * @ignore 8016760: failure of regression test langtools/tools/javac/T6725036.java |
jjg@71 | 28 | * @summary javac returns incorrect value for lastModifiedTime() when |
jjg@71 | 29 | * source is a zip file archive |
jjg@71 | 30 | */ |
jjg@71 | 31 | |
jjg@71 | 32 | import java.io.File; |
jjg@71 | 33 | import java.util.Date; |
jjg@71 | 34 | import java.util.jar.JarEntry; |
jjg@71 | 35 | import java.util.jar.JarFile; |
jjg@71 | 36 | import javax.tools.JavaFileObject; |
jjg@71 | 37 | |
jjg@71 | 38 | import com.sun.tools.javac.file.JavacFileManager; |
jjg@103 | 39 | import com.sun.tools.javac.file.RelativePath.RelativeFile; |
jjg@71 | 40 | import com.sun.tools.javac.file.ZipFileIndex; |
jjg@71 | 41 | import com.sun.tools.javac.file.ZipFileIndexArchive; |
jjg@839 | 42 | import com.sun.tools.javac.file.ZipFileIndexCache; |
jjg@71 | 43 | import com.sun.tools.javac.util.Context; |
jjg@71 | 44 | |
jjg@71 | 45 | public class T6725036 { |
jjg@71 | 46 | public static void main(String... args) throws Exception { |
jjg@71 | 47 | new T6725036().run(); |
jjg@71 | 48 | } |
jjg@71 | 49 | |
jjg@71 | 50 | void run() throws Exception { |
jjg@103 | 51 | RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class"); |
jjg@71 | 52 | |
jjg@71 | 53 | File f = new File(System.getProperty("java.home")); |
jjg@71 | 54 | if (!f.getName().equals("jre")) |
jjg@71 | 55 | f = new File(f, "jre"); |
jjg@71 | 56 | File rt_jar = new File(new File(f, "lib"), "rt.jar"); |
jjg@71 | 57 | |
jjg@71 | 58 | JarFile j = new JarFile(rt_jar); |
jjg@103 | 59 | JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); |
jjg@71 | 60 | long jarEntryTime = je.getTime(); |
jjg@71 | 61 | |
jjg@839 | 62 | ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance(); |
jjg@839 | 63 | ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false); |
jjg@71 | 64 | long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME); |
jjg@71 | 65 | |
jjg@103 | 66 | check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime); |
jjg@71 | 67 | |
jjg@71 | 68 | Context context = new Context(); |
jjg@71 | 69 | JavacFileManager fm = new JavacFileManager(context, false, null); |
jjg@71 | 70 | ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi); |
jjg@71 | 71 | JavaFileObject jfo = |
jjg@103 | 72 | zfia.getFileObject(TEST_ENTRY_NAME.dirname(), |
jjg@103 | 73 | TEST_ENTRY_NAME.basename()); |
jjg@71 | 74 | long jfoTime = jfo.getLastModified(); |
jjg@71 | 75 | |
jjg@71 | 76 | check(je, jarEntryTime, jfo, jfoTime); |
jjg@71 | 77 | |
jjg@71 | 78 | if (errors > 0) |
jjg@71 | 79 | throw new Exception(errors + " occurred"); |
jjg@71 | 80 | } |
jjg@71 | 81 | |
jjg@71 | 82 | void check(Object ref, long refTime, Object test, long testTime) { |
jjg@71 | 83 | if (refTime == testTime) |
jjg@71 | 84 | return; |
jjg@71 | 85 | System.err.println("Error: "); |
jjg@71 | 86 | System.err.println("Expected: " + getText(ref, refTime)); |
jjg@71 | 87 | System.err.println(" Found: " + getText(test, testTime)); |
jjg@71 | 88 | errors++; |
jjg@71 | 89 | } |
jjg@71 | 90 | |
jjg@71 | 91 | String getText(Object x, long t) { |
jjg@71 | 92 | return String.format("%14d", t) + " (" + new Date(t) + ") from " + x; |
jjg@71 | 93 | } |
jjg@71 | 94 | |
jjg@71 | 95 | int errors; |
jjg@71 | 96 | } |