1 /* 2 * Copyright (c) 2011, 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 /* @test 25 * @bug 7023703 26 * @summary Valid code doesn't compile 27 * @compile/fail/ref=T7023703neg.out -XDrawDiagnostics T7023703neg.java 28 */ 29 30 class T7023703neg { 31 testForLoop(boolean cond)32 void testForLoop(boolean cond) { 33 final int bug; 34 final int bug2; 35 for (;cond;) { 36 final int item = 0; 37 bug2 = 1; //error 38 } 39 bug = 0; //ok 40 } 41 testForEachLoop(java.util.Collection<Integer> c)42 void testForEachLoop(java.util.Collection<Integer> c) { 43 final int bug; 44 final int bug2; 45 for (Integer i : c) { 46 final int item = 0; 47 bug2 = 1; //error 48 } 49 bug = 0; //ok 50 } 51 testWhileLoop(boolean cond)52 void testWhileLoop(boolean cond) { 53 final int bug; 54 final int bug2; 55 while (cond) { 56 final int item = 0; 57 bug2 = 1; //error 58 } 59 bug = 0; //ok 60 } 61 testDoWhileLoop(boolean cond)62 void testDoWhileLoop(boolean cond) { 63 final int bug; 64 final int bug2; 65 do { 66 final int item = 0; 67 bug2 = 1; //error 68 } while (cond); 69 bug = 0; //ok 70 } 71 } 72