IncCompInheritance.java revision 2958:27da0c3ac83a
1/*
2 * Copyright (c) 2014, 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.  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 */
25
26/*
27 * @test
28 * @bug 8056258
29 * @summary Analysis of public API does not take super classes into account
30 * @library /tools/lib
31 * @modules jdk.compiler/com.sun.tools.javac.api
32 *          jdk.compiler/com.sun.tools.javac.file
33 *          jdk.compiler/com.sun.tools.javac.main
34 * @build Wrapper ToolBox
35 * @run main Wrapper IncCompInheritance
36 */
37
38import java.nio.file.Path;
39import java.nio.file.Paths;
40
41public class IncCompInheritance extends SjavacBase {
42    public static void main(String... args) throws Exception {
43
44        Path root = Paths.get(IncCompInheritance.class.getSimpleName() + "Test");
45        Path src = root.resolve("src");
46        Path classes = root.resolve("classes");
47
48        // Prep source files: A <- B <- C
49        String a = "package pkga; public class A { public void m() {} }";
50        String b = "package pkgb; public class B extends pkga.A {}";
51        String c = "package pkgc; public class C extends pkgb.B {{ new pkgb.B().m(); }}";
52        toolbox.writeFile(src.resolve("pkga/A.java"), a);
53        toolbox.writeFile(src.resolve("pkgb/B.java"), b);
54        toolbox.writeFile(src.resolve("pkgc/C.java"), c);
55
56        // Initial compile (should succeed)
57        String server = "--server:portfile=testserver,background=false";
58        int rc1 = compile(server, "-d", classes, src);
59        if (rc1 != 0)
60            throw new AssertionError("Compilation failed unexpectedly");
61
62        // Remove method A.m
63        Thread.sleep(2500); // Make sure we get a new timestamp
64        String aModified = "package pkga; public class A { }";
65        toolbox.writeFile(src.resolve("pkga/A.java"), aModified);
66
67        // Incremental compile (C should now be recompiled even though it
68        // depends on A only through inheritance via B).
69        // Since A.m is removed, this should fail.
70        int rc2 = compile(server, "-d", classes, src);
71        if (rc2 == 0)
72            throw new AssertionError("Compilation succeeded unexpectedly");
73    }
74}
75