|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 7194212 |
| 27 | + * @summary Ensure InnerClasses attribute does not overwrite flags |
| 28 | + * for source based classes |
| 29 | + * @library /tools/lib |
| 30 | + * @modules |
| 31 | + * jdk.compiler/com.sun.tools.javac.api |
| 32 | + * jdk.compiler/com.sun.tools.javac.main |
| 33 | + * @build toolbox.ToolBox toolbox.JavacTask |
| 34 | + * @run main T7194212 |
| 35 | + */ |
| 36 | + |
| 37 | +import toolbox.JavacTask; |
| 38 | +import toolbox.TestRunner; |
| 39 | +import toolbox.ToolBox; |
| 40 | + |
| 41 | +import java.nio.file.Files; |
| 42 | +import java.nio.file.Path; |
| 43 | +import java.nio.file.Paths; |
| 44 | + |
| 45 | +public class T7194212 extends TestRunner { |
| 46 | + |
| 47 | + protected ToolBox tb; |
| 48 | + |
| 49 | + T7194212() { |
| 50 | + super(System.err); |
| 51 | + tb = new ToolBox(); |
| 52 | + } |
| 53 | + |
| 54 | + public static void main(String... args) throws Exception { |
| 55 | + T7194212 t = new T7194212(); |
| 56 | + t.runTests(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Run all methods annotated with @Test, and throw an exception if any |
| 61 | + * errors are reported.. |
| 62 | + * |
| 63 | + * @throws Exception if any errors occurred |
| 64 | + */ |
| 65 | + protected void runTests() throws Exception { |
| 66 | + runTests(m -> new Object[] { Paths.get(m.getName()) }); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testSourceClassFileClash(Path base) throws Exception { |
| 71 | + Path src = base.resolve("src"); |
| 72 | + tb.writeJavaFiles(src, """ |
| 73 | + public class Outer { |
| 74 | + public class Inner { } |
| 75 | + } |
| 76 | + """); |
| 77 | + |
| 78 | + Path classes = base.resolve("classes"); |
| 79 | + |
| 80 | + Files.createDirectories(classes); |
| 81 | + |
| 82 | + new JavacTask(tb) |
| 83 | + .outdir(classes) |
| 84 | + .files(tb.findJavaFiles(src)) |
| 85 | + .run() |
| 86 | + .writeAll(); |
| 87 | + |
| 88 | + Path test = base.resolve("test"); |
| 89 | + tb.writeJavaFiles(test, """ |
| 90 | + public class Outer$Inner extends Outer { } |
| 91 | + """, |
| 92 | + """ |
| 93 | + public class Test extends Outer { } |
| 94 | + """); |
| 95 | + |
| 96 | + Path testClasses = base.resolve("test-classes"); |
| 97 | + |
| 98 | + Files.createDirectories(testClasses); |
| 99 | + |
| 100 | + new JavacTask(tb) |
| 101 | + .options("-classpath", classes.toString()) |
| 102 | + .outdir(testClasses) |
| 103 | + .files(tb.findJavaFiles(test)) |
| 104 | + .run() |
| 105 | + .writeAll(); |
| 106 | + } |
| 107 | +} |
0 commit comments