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