Mon, 12 May 2008 18:07:48 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Apr 25 15:22:39 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon May 12 18:07:48 2008 -0700 1.3 @@ -2863,13 +2863,15 @@ 1.4 JCExpressionStatement step = make.Exec(makeUnary(JCTree.PREINC, make.Ident(index))); 1.5 1.6 Type elemtype = types.elemtype(tree.expr.type); 1.7 - JCStatement loopvarinit = make. 1.8 - VarDef(tree.var.sym, 1.9 - make. 1.10 - Indexed(make.Ident(arraycache), make.Ident(index)). 1.11 - setType(elemtype)); 1.12 + JCExpression loopvarinit = make.Indexed(make.Ident(arraycache), 1.13 + make.Ident(index)).setType(elemtype); 1.14 + JCVariableDecl loopvardef = (JCVariableDecl)make.VarDef(tree.var.mods, 1.15 + tree.var.name, 1.16 + tree.var.vartype, 1.17 + loopvarinit).setType(tree.var.type); 1.18 + loopvardef.sym = tree.var.sym; 1.19 JCBlock body = make. 1.20 - Block(0, List.of(loopvarinit, tree.body)); 1.21 + Block(0, List.of(loopvardef, tree.body)); 1.22 1.23 result = translate(make. 1.24 ForLoop(loopinit, 1.25 @@ -2944,7 +2946,11 @@ 1.26 JCExpression vardefinit = make.App(make.Select(make.Ident(itvar), next)); 1.27 if (iteratorTarget != syms.objectType) 1.28 vardefinit = make.TypeCast(iteratorTarget, vardefinit); 1.29 - JCVariableDecl indexDef = make.VarDef(tree.var.sym, vardefinit); 1.30 + JCVariableDecl indexDef = (JCVariableDecl)make.VarDef(tree.var.mods, 1.31 + tree.var.name, 1.32 + tree.var.vartype, 1.33 + vardefinit).setType(tree.var.type); 1.34 + indexDef.sym = tree.var.sym; 1.35 JCBlock body = make.Block(0, List.of(indexDef, tree.body)); 1.36 result = translate(make. 1.37 ForLoop(List.of(init),
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/foreach/T6682380.java Mon May 12 18:07:48 2008 -0700 2.3 @@ -0,0 +1,45 @@ 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 6682380 6679509 2.30 + * @summary Foreach loop with generics inside finally block crashes javac with -target 1.5 2.31 + * @author Jan Lahoda, Maurizio Cimadamore 2.32 + * @compile -target 1.5 T6682380.java 2.33 + */ 2.34 + 2.35 +import java.util.List; 2.36 + 2.37 +public class T6682380<X> { 2.38 + 2.39 + public static void main(String[] args) { 2.40 + try { 2.41 + } finally { 2.42 + List<T6682380<?>> l = null; 2.43 + T6682380<?>[] a = null; 2.44 + for (T6682380<?> e1 : l); 2.45 + for (T6682380<?> e2 : a); 2.46 + } 2.47 + } 2.48 +}