Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
1 /*
2 * Copyright (c) 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 /*
27 * @test
28 * @bug 8013394
29 * @summary compile of iterator use fails with error "defined in an inaccessible class or interface"
30 * @library /tools/javac/lib
31 * @build ToolBox
32 * @run main CompileErrorWithIteratorTest
33 */
35 public class CompileErrorWithIteratorTest {
37 private static final String TestCollectionSrc =
38 "package pkg;\n" +
40 "import java.util.Iterator;\n" +
41 "import java.util.NoSuchElementException;\n" +
43 "public class TestCollection<E> implements Iterable<E> {\n" +
44 " public testCollectionIterator iterator() {\n" +
45 " return new testCollectionIterator();\n" +
46 " }\n" +
47 " class testCollectionIterator implements Iterator<E> {\n" +
48 " public boolean hasNext() { return true; }\n" +
49 " public E next() throws NoSuchElementException\n" +
50 " {\n" +
51 " return null;\n" +
52 " }\n" +
53 " public void remove() {}\n" +
54 " }\n" +
55 "}";
57 private static final String TestSrc =
58 "import pkg.TestCollection;\n" +
59 "\n" +
60 "public class Test {\n" +
61 "\n" +
62 " public static void main(String[] args) {\n" +
63 " TestCollection<String> tc1 = new TestCollection<String>();\n" +
64 " for (String s : tc1) {\n" +
65 " System.out.println(s);\n" +
66 " }\n" +
67 " }\n" +
68 "}";
70 public static void main(String args[]) throws Exception {
71 new CompileErrorWithIteratorTest().run();
72 }
74 void run() throws Exception {
75 compile();
76 }
78 void compile() throws Exception {
79 ToolBox.JavaToolArgs javacParams =
80 new ToolBox.JavaToolArgs()
81 .setSources(TestCollectionSrc, TestSrc);
82 ToolBox.javac(javacParams);
83 }
85 }