langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
changeset 42824 89b14017e8d6
parent 41943 a4ee110842fb
child 42827 36468b5fa7f4
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Dec 16 08:17:55 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Dec 16 12:02:30 2016 +0100
@@ -1983,22 +1983,42 @@
         } catch (ClassFinder.BadClassFile err) {
             throw err;
         } catch (CompletionFailure ex) {
-            //even if a class cannot be found in the current module and packages in modules it depends on that
-            //are exported for any or this module, the class may exist internally in some of these modules,
-            //or may exist in a module on which this module does not depend. Provide better diagnostic in
-            //such cases by looking for the class in any module:
-            for (ModuleSymbol ms : syms.getAllModules()) {
-                //do not load currently unloaded classes, to avoid too eager completion of random things in other modules:
-                ClassSymbol clazz = syms.getClass(ms, name);
-
-                if (clazz != null) {
-                    return new AccessError(clazz);
-                }
+            Symbol candidate = recoveryLoadClass.loadClass(env, name);
+
+            if (candidate != null) {
+                return candidate;
             }
+
             return typeNotFound;
         }
     }
 
+    public static interface RecoveryLoadClass {
+        Symbol loadClass(Env<AttrContext> env, Name name);
+    }
+
+    private RecoveryLoadClass recoveryLoadClass = (env, name) -> {
+        //even if a class cannot be found in the current module and packages in modules it depends on that
+        //are exported for any or this module, the class may exist internally in some of these modules,
+        //or may exist in a module on which this module does not depend. Provide better diagnostic in
+        //such cases by looking for the class in any module:
+        for (ModuleSymbol ms : syms.getAllModules()) {
+            //do not load currently unloaded classes, to avoid too eager completion of random things in other modules:
+            ClassSymbol clazz = syms.getClass(ms, name);
+
+            if (clazz != null) {
+                return new AccessError(clazz);
+            }
+        }
+        return null;
+    };
+
+    public RecoveryLoadClass setRecoveryLoadClass(RecoveryLoadClass recovery) {
+        RecoveryLoadClass prev = recoveryLoadClass;
+        recoveryLoadClass = recovery;
+        return prev;
+    }
+
     /**
      * Find a type declared in a scope (not inherited).  Return null
      * if none is found.