src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java
changeset 54339 f69a2f675f19
parent 52489 1a6aeca4a8c9
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Tue Mar 26 12:12:49 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Fri Mar 29 07:38:34 2019 -0700
@@ -33,6 +33,7 @@
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import java.util.function.Supplier;
 
 import javax.lang.model.SourceVersion;
 import javax.tools.JavaFileManager;
@@ -222,7 +223,7 @@
         jrtIndex = useCtProps && JRTIndex.isAvailable() ? JRTIndex.getSharedInstance() : null;
 
         profile = Profile.instance(context);
-        cachedCompletionFailure = new CompletionFailure(null, (JCDiagnostic) null, dcfh);
+        cachedCompletionFailure = new CompletionFailure(null, () -> null, dcfh);
         cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
     }
 
@@ -298,9 +299,12 @@
             try {
                 fillIn(p);
             } catch (IOException ex) {
-                JCDiagnostic msg =
-                        diagFactory.fragment(Fragments.ExceptionMessage(ex.getLocalizedMessage()));
-                throw new CompletionFailure(sym, msg, dcfh).initCause(ex);
+                throw new CompletionFailure(
+                        sym,
+                        () -> diagFactory.fragment(
+                            Fragments.ExceptionMessage(ex.getLocalizedMessage())),
+                        dcfh)
+                    .initCause(ex);
             }
         }
         if (!reader.filling)
@@ -337,9 +341,8 @@
      */
     void fillIn(ClassSymbol c) {
         if (completionFailureName == c.fullname) {
-            JCDiagnostic msg =
-                    diagFactory.fragment(Fragments.UserSelectedCompletionFailure);
-            throw new CompletionFailure(c, msg, dcfh);
+            throw new CompletionFailure(
+                c, () -> diagFactory.fragment(Fragments.UserSelectedCompletionFailure), dcfh);
         }
         currentOwner = c;
         JavaFileObject classfile = c.classfile;
@@ -390,16 +393,15 @@
     }
     // where
         private CompletionFailure classFileNotFound(ClassSymbol c) {
-            JCDiagnostic diag =
-                diagFactory.fragment(Fragments.ClassFileNotFound(c.flatname));
-            return newCompletionFailure(c, diag);
+            return newCompletionFailure(
+                c, () -> diagFactory.fragment(Fragments.ClassFileNotFound(c.flatname)));
         }
         /** Static factory for CompletionFailure objects.
          *  In practice, only one can be used at a time, so we share one
          *  to reduce the expense of allocating new exception objects.
          */
         private CompletionFailure newCompletionFailure(TypeSymbol c,
-                                                       JCDiagnostic diag) {
+                                                       Supplier<JCDiagnostic> diag) {
             if (!cacheCompletionFailure) {
                 // log.warning("proc.messager",
                 //             Log.getLocalizedString("class.file.not.found", c.flatname));
@@ -408,7 +410,7 @@
             } else {
                 CompletionFailure result = cachedCompletionFailure;
                 result.sym = c;
-                result.diag = diag;
+                result.resetDiagnostic(diag);
                 return result;
             }
         }
@@ -782,7 +784,7 @@
 
         public BadClassFile(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag,
                 JCDiagnostic.Factory diagFactory, DeferredCompletionFailureHandler dcfh) {
-            super(sym, createBadClassFileDiagnostic(file, diag, diagFactory), dcfh);
+            super(sym, () -> createBadClassFileDiagnostic(file, diag, diagFactory), dcfh);
         }
         // where
         private static JCDiagnostic createBadClassFileDiagnostic(