8148131: compilation result depends on order of sources
authorjlahoda
Mon, 04 Jul 2016 08:52:45 +0200
changeset 39371 ac04aefa4ba6
parent 39370 437ba9bd2582
child 39372 a42db8c180c3
8148131: compilation result depends on order of sources Summary: Complete during imports phase should not trigger the hierarchy phase Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java
langtools/test/tools/javac/importscope/T8148131/A.java
langtools/test/tools/javac/importscope/T8148131/B.java
langtools/test/tools/javac/importscope/T8148131/C.java
langtools/test/tools/javac/importscope/T8148131/D.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Jul 01 14:41:07 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Mon Jul 04 08:52:45 2016 +0200
@@ -241,7 +241,14 @@
         public final List<Env<AttrContext>> completeEnvs(List<Env<AttrContext>> envs) {
             boolean firstToComplete = queue.isEmpty();
 
-            doCompleteEnvs(envs);
+            Phase prevTopLevelPhase = topLevelPhase;
+
+            try {
+                topLevelPhase = this;
+                doCompleteEnvs(envs);
+            } finally {
+                topLevelPhase = prevTopLevelPhase;
+            }
 
             if (firstToComplete) {
                 List<Env<AttrContext>> out = queue.toList();
@@ -278,6 +285,7 @@
     }
 
     private final ImportsPhase completeClass = new ImportsPhase();
+    private Phase topLevelPhase;
 
     /**Analyze import clauses.
      */
@@ -773,6 +781,15 @@
 
         @Override
         public void complete(Symbol sym) throws CompletionFailure {
+            Assert.check((topLevelPhase instanceof ImportsPhase) ||
+                         (topLevelPhase == this));
+
+            if (topLevelPhase != this) {
+                //only do the processing based on dependencies in the HierarchyPhase:
+                sym.completer = this;
+                return ;
+            }
+
             Env<AttrContext> env = typeEnvs.get((ClassSymbol) sym);
 
             super.doCompleteEnvs(List.of(env));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/importscope/T8148131/A.java	Mon Jul 04 08:52:45 2016 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8148131
+ * @summary Ensuring order of inputs does not affect compilability of the sources
+ * @compile A.java B.java C.java D.java
+ * @compile A.java B.java D.java C.java
+ * @compile A.java C.java B.java D.java
+ * @compile A.java C.java D.java B.java
+ * @compile A.java D.java B.java C.java
+ * @compile A.java D.java C.java B.java
+ * @compile D.java A.java B.java C.java
+ * @compile D.java A.java C.java B.java
+ * @compile D.java B.java A.java C.java
+ * @compile D.java B.java C.java A.java
+ * @compile D.java C.java B.java A.java
+ * @compile D.java C.java A.java B.java
+ */
+package pkg;
+
+import pkg.B.BInner;
+
+class A implements BInner {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/importscope/T8148131/B.java	Mon Jul 04 08:52:45 2016 +0200
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+class B implements C.DInner {
+  interface BInner {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/importscope/T8148131/C.java	Mon Jul 04 08:52:45 2016 +0200
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+class C extends D {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/importscope/T8148131/D.java	Mon Jul 04 08:52:45 2016 +0200
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+class D {
+  interface DInner {}
+}