IncCompInheritance.java revision 2656:a0125e2a10e8
1/*
2 * Copyright (c) 2014, 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 * @build Wrapper ToolBox
32 * @run main Wrapper IncCompInheritance
33 */
34
35import java.nio.file.Path;
36import java.nio.file.Paths;
37
38public class IncCompInheritance extends SjavacBase {
39    public static void main(String... args) throws Exception {
40
41        Path root = Paths.get(IncCompInheritance.class.getSimpleName() + "Test");
42        Path src = root.resolve("src");
43        Path classes = root.resolve("classes");
44
45        // Prep source files: A <- B <- C
46        String a = "package pkga; public class A { public void m() {} }";
47        String b = "package pkgb; public class B extends pkga.A {}";
48        String c = "package pkgc; public class C extends pkgb.B {{ new pkgb.B().m(); }}";
49        toolbox.writeFile(src.resolve("pkga/A.java"), a);
50        toolbox.writeFile(src.resolve("pkgb/B.java"), b);
51        toolbox.writeFile(src.resolve("pkgc/C.java"), c);
52
53        // Initial compile (should succeed)
54        String server = "--server:portfile=testserver,background=false";
55        int rc1 = compile(server, "-d", classes, src);
56        if (rc1 != 0)
57            throw new AssertionError("Compilation failed unexpectedly");
58
59        // Remove method A.m
60        String aModified = "package pkga; public class A { }";
61        toolbox.writeFile(src.resolve("pkga/A.java"), aModified);
62
63        // Incremental compile (C should now be recompiled even though it
64        // depends on A only through inheritance via B).
65        // Since A.m is removed, this should fail.
66        int rc2 = compile(server, "-d", classes, src);
67        if (rc2 == 0)
68            throw new AssertionError("Compilation succeeded unexpectedly");
69    }
70}
71