Wed, 02 Mar 2016 18:33:38 +0530
8066871: java.lang.VerifyError: Bad local variable type - local final String
Summary: baseType() erroneously called on MethodResultInfo causes lack of constant type info
Reviewed-by: jlahoda, mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Feb 05 09:34:47 2016 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Mar 02 18:33:38 2016 +0530 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -249,6 +249,7 @@ 1.11 * are correct. 1.12 * 1.13 * @param tree The tree whose kind and type is checked 1.14 + * @param found The computed type of the tree 1.15 * @param ownkind The computed kind of the tree 1.16 * @param resultInfo The expected result of the tree 1.17 */
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Feb 05 09:34:47 2016 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Mar 02 18:33:38 2016 +0530 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -1007,7 +1007,7 @@ 2.11 DeferredType dt = (DeferredType)found; 2.12 return dt.check(this); 2.13 } else { 2.14 - Type uResult = U(found.baseType()); 2.15 + Type uResult = U(found); 2.16 Type capturedType = pos == null || pos.getTree() == null ? 2.17 types.capture(uResult) : 2.18 checkContext.inferenceContext()
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/conditional/ConditionalWithFinalStrings.java Wed Mar 02 18:33:38 2016 +0530 3.3 @@ -0,0 +1,69 @@ 3.4 +/* 3.5 + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 8066871 3.30 + * @summary java.lang.VerifyError: Bad local variable type - local final String 3.31 + * @author Srikanth Sankaran 3.32 + * 3.33 + * @compile -g:none ConditionalWithFinalStrings.java 3.34 + * @run main ConditionalWithFinalStrings 3.35 + */ 3.36 + 3.37 +public class ConditionalWithFinalStrings { 3.38 + 3.39 + interface I { 3.40 + String foo(); 3.41 + } 3.42 + 3.43 + static class Tmp { 3.44 + private String value; 3.45 + public void setValue(String tmpStr) { 3.46 + this.value = tmpStr; 3.47 + if (!this.value.equals("YES")) 3.48 + throw new AssertionError(); 3.49 + } 3.50 + } 3.51 + 3.52 + void goo(I i) { 3.53 + if (!i.foo().equals("YES")) 3.54 + throw new AssertionError(); 3.55 + } 3.56 + 3.57 + public void test() { 3.58 + final String y = "YES"; 3.59 + final String n = "NO"; 3.60 + Tmp tmp = new Tmp(); 3.61 + tmp.setValue(true ? y : n); 3.62 + goo (() -> y); 3.63 + 3.64 + } 3.65 + public static void main(String[] args) { 3.66 + new ConditionalWithFinalStrings().test(); 3.67 + if (!id("Hello!").equals("Hello!")) 3.68 + throw new AssertionError(); 3.69 + 3.70 + } 3.71 + static <Z> Z id(Z z) { return z; } 3.72 +}