Skip to content

Commit

Permalink
Fix #846 Formatter leaks threads and memory
Browse files Browse the repository at this point in the history
I've signed the CLA.

Fixes #847

FUTURE_COPYBARA_INTEGRATE_REVIEW=#847 from stiemannkj1:fix-846-mem-thread-leak 0ca1e9b
PiperOrigin-RevId: 506946916
  • Loading branch information
cushon authored and google-java-format Team committed Feb 4, 2023
1 parent 4a22aab commit 3f6f7e1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/com/google/googlejavaformat/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.googlejavaformat.FormatterDiagnostic;
import com.google.googlejavaformat.java.JavaFormatterOptions.Style;
import java.io.IOError;
Expand All @@ -28,6 +29,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -187,6 +189,10 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti
outWriter.write(formatted);
}
}
if (!MoreExecutors.shutdownAndAwaitTermination(executorService, Duration.ofSeconds(5))) {
errWriter.println("Failed to shut down ExecutorService");
allOk = false;
}
return allOk ? 0 : 1;
}

Expand Down

0 comments on commit 3f6f7e1

Please sign in to comment.