mcimadamore@1297: /* mcimadamore@1297: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. mcimadamore@1297: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@1297: * mcimadamore@1297: * This code is free software; you can redistribute it and/or modify it mcimadamore@1297: * under the terms of the GNU General Public License version 2 only, as mcimadamore@1297: * published by the Free Software Foundation. mcimadamore@1297: * mcimadamore@1297: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@1297: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@1297: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@1297: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@1297: * accompanied this code). mcimadamore@1297: * mcimadamore@1297: * You should have received a copy of the GNU General Public License version mcimadamore@1297: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@1297: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@1297: * mcimadamore@1297: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mcimadamore@1297: * or visit www.oracle.com if you need additional information or have any mcimadamore@1297: * questions. mcimadamore@1297: */ mcimadamore@1297: mcimadamore@1297: /* mcimadamore@1297: * @test mcimadamore@1297: * @summary Integrate efectively final check with DA/DU analysis mcimadamore@1297: * @compile/fail/ref=EffectivelyFinalTest01.out -XDallowEffectivelyFinalInInnerClasses -XDrawDiagnostics EffectivelyFinalTest.java mcimadamore@1297: * @compile/fail/ref=EffectivelyFinalTest02.out -source 7 -Xlint:-options -XDrawDiagnostics EffectivelyFinalTest.java mcimadamore@1297: */ mcimadamore@1297: class EffectivelyFinalTest { mcimadamore@1297: mcimadamore@1297: void m1(int x) { mcimadamore@1297: int y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m2(int x) { mcimadamore@1297: int y; mcimadamore@1297: y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m3(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //error - y not DA mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m4(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: else y = 2; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m5(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: y = 2; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //error - y not EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m6(int x) { mcimadamore@1297: new Object() { { System.out.println(x+1); } }; //error - x not EF mcimadamore@1297: x++; mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m7(int x) { mcimadamore@1297: new Object() { { System.out.println(x=1); } }; //error - x not EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m8() { mcimadamore@1297: int y; mcimadamore@1297: new Object() { { System.out.println(y=1); } }; //error - y not EF mcimadamore@1297: } mcimadamore@1297: }