Skip to content

Commit 49fb440

Browse files
authored
Merge pull request #3 from pandening/develop
fix executorService
2 parents 8762b39 + d6d39c1 commit 49fb440

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: core/src/main/java/com/google/googlejavaformat/java/Formatter.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ public void formatSource(CharSource input, CharSink output)
236236
* @param timeoutForAll if true, total timeout is {@code timeout}, else timeout is {@code timeout * fileCount}
237237
* @return the formatted java source
238238
*/
239-
public List<String> formatSourceFile(String file, boolean useExecutor, boolean reWrite,
240-
long timeout, TimeUnit unit, boolean timeoutForAll)
239+
public List<String> formatSourceFile(String file, boolean useExecutor, ExecutorService executorService,
240+
boolean reWrite, long timeout, TimeUnit unit, boolean timeoutForAll)
241241
throws IOException, FormatterException {
242242
if (Strings.isNullOrEmpty(file)) {
243243
return Collections.emptyList();
@@ -248,6 +248,9 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
248248
unit = TimeUnit.SECONDS;
249249
timeoutForAll = false;
250250
}
251+
if (executorService == null) {
252+
executorService = EXECUTOR_SERVICE;
253+
}
251254
File sourceFile = new File(file);
252255
if (sourceFile.isFile()) {
253256
// this is a file
@@ -262,7 +265,7 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
262265
formatted = "";
263266
}
264267
return ImmutableList.of(formatted); // do not update the file source.
265-
}, EXECUTOR_SERVICE);
268+
}, executorService);
266269
try {
267270
if (formattedFuture.get(timeout, unit) == null) {
268271
return Collections.emptyList();
@@ -298,7 +301,7 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
298301
formatted = "";
299302
}
300303
return formatted;
301-
}, EXECUTOR_SERVICE));
304+
}, executorService));
302305
}
303306
// check the status.
304307
CompletableFuture<List<String>> formattedResultFuture =

0 commit comments

Comments
 (0)