ConditionalWithFinalStrings.java revision 2778:6a927a9114c1
1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8066871 27 * @summary java.lang.VerifyError: Bad local variable type - local final String 28 * @author Srikanth Sankaran 29 * 30 * @compile -g:none ConditionalWithFinalStrings.java 31 * @run main ConditionalWithFinalStrings 32 */ 33 34public class ConditionalWithFinalStrings { 35 36 interface I { 37 String foo(); 38 } 39 40 static class Tmp { 41 private String value; 42 public void setValue(String tmpStr) { 43 this.value = tmpStr; 44 if (!this.value.equals("YES")) 45 throw new AssertionError(); 46 } 47 } 48 49 void goo(I i) { 50 if (!i.foo().equals("YES")) 51 throw new AssertionError(); 52 } 53 54 public void test() { 55 final String y = "YES"; 56 final String n = "NO"; 57 Tmp tmp = new Tmp(); 58 tmp.setValue(true ? y : n); 59 goo (() -> y); 60 61 } 62 public static void main(String[] args) { 63 new ConditionalWithFinalStrings().test(); 64 if (!id("Hello!").equals("Hello!")) 65 throw new AssertionError(); 66 67 } 68 static <Z> Z id(Z z) { return z; } 69} 70