Repository: google/error-prone (language: java)

Issue:
Lazily load plugin checks when running auto-patching
When running in normal checking mode, Error Prone loads plugin checks lazily to delay the loading until after the javac file manager is initialized; see [here](https://github.com/google/error-prone/blob/8f9e7da16b81b9fd65cca5fef9a79a4e6019eabd/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java#L145-L159).  This change introduces the same lazy loading when running Error Prone in auto-patching mode.  In most scenarios I've seen, applying suggested fixes from plugin checks works fine, but when trying to generate patches on Bazel (see https://github.com/bazelbuild/bazel/pull/21640), things do not work without this change.  The previous code was "forcing" a `Supplier` and then re-wrapping the result in a `Supplier` again; this change mostly just gets rid of that.


Discussion / hints:

Fix patch:
diff --git a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
index c59458442d0..589542587e8 100644
--- a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
+++ b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java
@@ -72,22 +72,24 @@ public static ErrorProneAnalyzer createAnalyzer(
     refactoringCollection[0] = RefactoringCollection.refactor(epOptions.patchingOptions(), context);
 
     // Refaster refactorer or using builtin checks
-    CodeTransformer codeTransformer =
+    Supplier<CodeTransformer> codeTransformer =
         epOptions
             .patchingOptions()
             .customRefactorer()
             .or(
-                () -> {
-                  ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context);
-                  ImmutableSet<String> namedCheckers = epOptions.patchingOptions().namedCheckers();
-                  if (!namedCheckers.isEmpty()) {
-                    toUse = toUse.filter(bci -> namedCheckers.contains(bci.canonicalName()));
-                  } else {
-                    toUse = toUse.applyOverrides(epOptions);
-                  }
-                  return ErrorProneScannerTransformer.create(toUse.get());
-                })
-            .get();
+                Suppliers.memoize(
+                    () -> {
+                      ScannerSupplier toUse =
+                          ErrorPronePlugins.loadPlugins(scannerSupplier, context);
+                      ImmutableSet<String> namedCheckers =
+                          epOptions.patchingOptions().namedCheckers();
+                      if (!namedCheckers.isEmpty()) {
+                        toUse = toUse.filter(bci -> namedCheckers.contains(bci.canonicalName()));
+                      } else {
+                        toUse = toUse.applyOverrides(epOptions);
+                      }
+                      return ErrorProneScannerTransformer.create(toUse.get());
+                    }));
 
     return createWithCustomDescriptionListener(
         codeTransformer, epOptions, context, refactoringCollection[0]);
@@ -160,15 +162,12 @@ private static Supplier<CodeTransformer> scansPlugins(
   }
 
   static ErrorProneAnalyzer createWithCustomDescriptionListener(
-      CodeTransformer codeTransformer,
+      Supplier<CodeTransformer> codeTransformer,
       ErrorProneOptions errorProneOptions,
       Context context,
       DescriptionListener.Factory descriptionListenerFactory) {
     return new ErrorProneAnalyzer(
-        Suppliers.ofInstance(codeTransformer),
-        errorProneOptions,
-        context,
-        descriptionListenerFactory);
+        codeTransformer, errorProneOptions, context, descriptionListenerFactory);
   }
 
   private ErrorProneAnalyzer(


Test patch: