Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 15 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 @@ -35,6 +36,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/** The main class for the Java formatter CLI. */
public final class Main {
Expand Down Expand Up @@ -187,6 +189,19 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti
outWriter.write(formatted);
}
}

// #846 Clean up any resources and threads created by the executorService.
final boolean completedShutdown =
MoreExecutors.shutdownAndAwaitTermination(executorService, 100, TimeUnit.MILLISECONDS);

if (!completedShutdown) {
// We wait for all formatting tasks to complete when looping through the formatting tasks
// before shutdown, so no tasks should be left over by the time we shut down the executor
// service.
throw new IllegalStateException(
"Failed to complete all formatting tasks and shut down the formatter.");
}

return allOk ? 0 : 1;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.