Add error-prone annotations to format strings in LocalSpawnRunner

Add proper annotations for string parameters and standardize the logging
methods to comply with StringFormat convention for parameters. Refactor callers
to the logging methods to properly order parameters and delegate string
formatting to the log methods.

RELNOTES: none.
PiperOrigin-RevId: 241740728
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/BUILD b/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
index 7b79bd3..9ef0881 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
@@ -28,6 +28,7 @@
         "//src/main/java/com/google/devtools/build/lib/profiler",
         "//src/main/java/com/google/devtools/build/lib/shell",
         "//src/main/java/com/google/devtools/build/lib/vfs",
+        "//third_party:error_prone_annotations",
         "//third_party:guava",
         "//third_party:jsr305",
     ],
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
index cd55665..eb92c7c 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
@@ -46,6 +46,8 @@
 import com.google.devtools.build.lib.util.OsUtils;
 import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.Path;
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -189,23 +191,25 @@
       try {
         return start();
       } catch (Error e) {
-        stepLog(SEVERE, UNHANDLED_EXCEPTION_MSG, e);
+        stepLog(SEVERE, e, UNHANDLED_EXCEPTION_MSG);
         throw e;
       } catch (IOException e) {
-        stepLog(SEVERE, "Local I/O error", e);
+        stepLog(SEVERE, e, "Local I/O error");
         throw e;
       } catch (RuntimeException e) {
-        stepLog(SEVERE, UNHANDLED_EXCEPTION_MSG, e);
+        stepLog(SEVERE, e, UNHANDLED_EXCEPTION_MSG);
         throw new RuntimeException(UNHANDLED_EXCEPTION_MSG, e);
       }
     }
 
-    private void stepLog(Level level, String fmt, Object... args) {
-      stepLog(level, fmt, /*cause=*/ null, args);
+    @FormatMethod
+    private void stepLog(Level level, @FormatString String fmt, Object... args) {
+      stepLog(level, /*cause=*/ null, fmt, args);
     }
 
-    @SuppressWarnings("unused")
-    private void stepLog(Level level, String fmt, @Nullable Throwable cause, Object... args) {
+    @FormatMethod
+    private void stepLog(
+        Level level, @Nullable Throwable cause, @FormatString String fmt, Object... args) {
       String msg = String.format(fmt, args);
       String toLog = String.format("%s (#%d %s)", msg, id, desc());
       logger.log(level, toLog, cause);
@@ -402,11 +406,10 @@
           // We can't handle this exception in any meaningful way, nor should we, but let's log it.
           stepLog(
               WARNING,
-              String.format(
-                  "failed to delete temp directory '%s'; this might indicate that the action "
-                      + "created subprocesses that didn't terminate and hold files open in that "
-                      + "directory",
-                  tmpDir));
+              "failed to delete temp directory '%s'; this might indicate that the action "
+                  + "created subprocesses that didn't terminate and hold files open in that "
+                  + "directory",
+              tmpDir);
         }
       }
     }