Fri, 08 Aug 2008 17:48:04 +0100
6734819: Javac performs flows analysis on already translated classes
Summary: Regression in JavaCompiler.desugar introduced in 6726015
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Aug 08 17:43:24 2008 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Aug 08 17:48:04 2008 +0100 1.3 @@ -27,6 +27,7 @@ 1.4 1.5 import java.io.*; 1.6 import java.util.HashSet; 1.7 +import java.util.LinkedHashSet; 1.8 import java.util.LinkedHashMap; 1.9 import java.util.Map; 1.10 import java.util.MissingResourceException; 1.11 @@ -1185,14 +1186,16 @@ 1.12 * are processed through attribute and flow before subtypes are translated. 1.13 */ 1.14 class ScanNested extends TreeScanner { 1.15 - Set<Env<AttrContext>> dependencies = new HashSet<Env<AttrContext>>(); 1.16 + Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); 1.17 public void visitClassDef(JCClassDecl node) { 1.18 Type st = types.supertype(node.sym.type); 1.19 if (st.tag == TypeTags.CLASS) { 1.20 ClassSymbol c = st.tsym.outermostClass(); 1.21 Env<AttrContext> stEnv = enter.getEnv(c); 1.22 - if (stEnv != null && env != stEnv) 1.23 - dependencies.add(stEnv); 1.24 + if (stEnv != null && env != stEnv) { 1.25 + if (dependencies.add(stEnv)) 1.26 + scan(stEnv.tree); 1.27 + } 1.28 } 1.29 super.visitClassDef(node); 1.30 } 1.31 @@ -1204,6 +1207,11 @@ 1.32 flow(attribute(dep)); 1.33 } 1.34 1.35 + //We need to check for error another time as more classes might 1.36 + //have been attributed and analyzed at this stage 1.37 + if (errorCount() > 0) 1.38 + return; 1.39 + 1.40 if (verboseCompilePolicy) 1.41 log.printLines(log.noticeWriter, "[desugar " + env.enclClass.sym + "]"); 1.42
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/6734819/T6734819a.java Fri Aug 08 17:48:04 2008 +0100 2.3 @@ -0,0 +1,39 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6734819 2.30 + * @summary Javac performs flows analysis on already translated classes 2.31 + * @author Maurizio Cimadamore 2.32 + * 2.33 + * @compile/ref=T6734819a.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819a.java 2.34 + */ 2.35 +class Y extends W {} 2.36 +class W extends Z {} 2.37 + 2.38 +class Z { 2.39 + void m(Z z) { 2.40 + W w = (W)z; 2.41 + } 2.42 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/6734819/T6734819a.out Fri Aug 08 17:48:04 2008 +0100 3.3 @@ -0,0 +1,12 @@ 3.4 +[attribute Y] 3.5 +[flow Y] 3.6 +[attribute W] 3.7 +[flow W] 3.8 +[attribute Z] 3.9 +[flow Z] 3.10 +[desugar Y] 3.11 +[generate code Y] 3.12 +[desugar W] 3.13 +[generate code W] 3.14 +[desugar Z] 3.15 +[generate code Z]
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/6734819/T6734819b.java Fri Aug 08 17:48:04 2008 +0100 4.3 @@ -0,0 +1,35 @@ 4.4 +/* 4.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 4.24 + * have any questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 6734819 4.30 + * @summary Javac performs flows analysis on already translated classes 4.31 + * @author Maurizio Cimadamore 4.32 + * 4.33 + * @compile/ref=T6734819b.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819b.java 4.34 + */ 4.35 +class A extends B {} 4.36 +class B { 4.37 + class C extends B {} 4.38 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/6734819/T6734819b.out Fri Aug 08 17:48:04 2008 +0100 5.3 @@ -0,0 +1,9 @@ 5.4 +[attribute A] 5.5 +[flow A] 5.6 +[attribute B] 5.7 +[flow B] 5.8 +[desugar A] 5.9 +[generate code A] 5.10 +[desugar B] 5.11 +[generate code B] 5.12 +[generate code B]
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/6734819/T6734819c.java Fri Aug 08 17:48:04 2008 +0100 6.3 @@ -0,0 +1,40 @@ 6.4 +/* 6.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 6.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 6.24 + * have any questions. 6.25 + */ 6.26 + 6.27 +/* 6.28 + * @test 6.29 + * @bug 6734819 6.30 + * @summary Javac performs flows analysis on already translated classes 6.31 + * @author Maurizio Cimadamore 6.32 + * 6.33 + * @compile/fail/ref=T6734819c.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819c.java 6.34 + */ 6.35 +class Y extends W {} 6.36 +class W extends Z {} 6.37 + 6.38 +class Z { 6.39 + void m(Z z) { 6.40 + return; 6.41 + W w = (W)z; 6.42 + } 6.43 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/6734819/T6734819c.out Fri Aug 08 17:48:04 2008 +0100 7.3 @@ -0,0 +1,8 @@ 7.4 +[attribute Y] 7.5 +[flow Y] 7.6 +[attribute W] 7.7 +[flow W] 7.8 +[attribute Z] 7.9 +[flow Z] 7.10 +T6734819c.java:38:11: compiler.err.unreachable.stmt 7.11 +1 error