Mon, 02 Sep 2013 22:44:06 +0100
8022162: Incorrect signature determination for certain inner class generics
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon Sep 02 22:38:36 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon Sep 02 22:44:06 2013 +0100 1.3 @@ -727,12 +727,14 @@ 1.4 ClassSymbol t = enterClass(names.fromUtf(signatureBuffer, 1.5 startSbp, 1.6 sbp - startSbp)); 1.7 - if (outer == Type.noType) 1.8 - outer = t.erasure(types); 1.9 - else 1.10 - outer = new ClassType(outer, List.<Type>nil(), t); 1.11 - sbp = startSbp; 1.12 - return outer; 1.13 + 1.14 + try { 1.15 + return (outer == Type.noType) ? 1.16 + t.erasure(types) : 1.17 + new ClassType(outer, List.<Type>nil(), t); 1.18 + } finally { 1.19 + sbp = startSbp; 1.20 + } 1.21 } 1.22 1.23 case '<': // generic arguments 1.24 @@ -797,6 +799,13 @@ 1.25 continue; 1.26 1.27 case '.': 1.28 + //we have seen an enclosing non-generic class 1.29 + if (outer != Type.noType) { 1.30 + t = enterClass(names.fromUtf(signatureBuffer, 1.31 + startSbp, 1.32 + sbp - startSbp)); 1.33 + outer = new ClassType(outer, List.<Type>nil(), t); 1.34 + } 1.35 signatureBuffer[sbp++] = (byte)'$'; 1.36 continue; 1.37 case '/':
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T8022162/IncorrectSignatureDeterminationForInnerClassesTest.java Mon Sep 02 22:44:06 2013 +0100 2.3 @@ -0,0 +1,89 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8022162 2.30 + * @summary Incorrect signature determination for certain inner class generics 2.31 + * @library /tools/javac/lib 2.32 + * @build ToolBox 2.33 + * @run main IncorrectSignatureDeterminationForInnerClassesTest 2.34 + */ 2.35 + 2.36 +import java.nio.file.Files; 2.37 +import java.nio.file.Paths; 2.38 + 2.39 +public class IncorrectSignatureDeterminationForInnerClassesTest { 2.40 + 2.41 + private static final String DSrc = 2.42 + "package p1;\n" + 2.43 + 2.44 + "public class D<T> {\n" + 2.45 + "}\n" + 2.46 + 2.47 + "abstract class Q<T> {\n" + 2.48 + " protected void m(M.E e) {}\n" + 2.49 + 2.50 + " public class M extends D<T> {\n" + 2.51 + " public class E {}\n" + 2.52 + " }\n" + 2.53 + "}"; 2.54 + 2.55 + private static final String HSrc = 2.56 + "package p1;\n" + 2.57 + 2.58 + "public class H {\n" + 2.59 + " static class EQ extends Q<Object> {\n" + 2.60 + " private void m2(M.E item) {\n" + 2.61 + " m(item);\n" + 2.62 + " }\n" + 2.63 + " }\n" + 2.64 + "}"; 2.65 + 2.66 + public static void main(String args[]) throws Exception { 2.67 + new IncorrectSignatureDeterminationForInnerClassesTest().run(); 2.68 + } 2.69 + 2.70 + void run() throws Exception { 2.71 + compile(); 2.72 + } 2.73 + 2.74 + void compile() throws Exception { 2.75 + Files.createDirectory(Paths.get("classes")); 2.76 + 2.77 + ToolBox.JavaToolArgs javacParams = 2.78 + new ToolBox.JavaToolArgs() 2.79 + .appendArgs("-d", "classes") 2.80 + .setSources(DSrc); 2.81 + 2.82 + ToolBox.javac(javacParams); 2.83 + 2.84 + // compile class H against the class files for classes D and Q 2.85 + javacParams = 2.86 + new ToolBox.JavaToolArgs() 2.87 + .appendArgs("-d", "classes", "-cp", "classes") 2.88 + .setSources(HSrc); 2.89 + ToolBox.javac(javacParams); 2.90 + } 2.91 + 2.92 +}