File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
core/src/main/java/com/google/googlejavaformat/java Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1818import static java .nio .charset .StandardCharsets .UTF_8 ;
1919
2020import com .google .common .io .ByteStreams ;
21+ import com .google .common .util .concurrent .MoreExecutors ;
2122import com .google .googlejavaformat .FormatterDiagnostic ;
2223import com .google .googlejavaformat .java .JavaFormatterOptions .Style ;
2324import java .io .IOError ;
3536import java .util .concurrent .ExecutorService ;
3637import java .util .concurrent .Executors ;
3738import java .util .concurrent .Future ;
39+ import java .util .concurrent .TimeUnit ;
3840
3941/** The main class for the Java formatter CLI. */
4042public final class Main {
@@ -187,6 +189,19 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti
187189 outWriter .write (formatted );
188190 }
189191 }
192+
193+ // #846 Clean up any resources and threads created by the executorService.
194+ final boolean completedShutdown =
195+ MoreExecutors .shutdownAndAwaitTermination (executorService , 100 , TimeUnit .MILLISECONDS );
196+
197+ if (!completedShutdown ) {
198+ // We wait for all formatting tasks to complete when looping through the formatting tasks
199+ // before shutdown, so no tasks should be left over by the time we shut down the executor
200+ // service.
201+ throw new IllegalStateException (
202+ "Failed to complete all formatting tasks and shut down the formatter." );
203+ }
204+
190205 return allOk ? 0 : 1 ;
191206 }
192207
You can’t perform that action at this time.
0 commit comments