Skip to content

Commit 0e6b460

Browse files
committed
don't reuse buf step args between calls
1 parent 6579264 commit 0e6b460

File tree

1 file changed

+12
-13
lines changed
  • lib/src/main/java/com/diffplug/spotless/protobuf

1 file changed

+12
-13
lines changed

lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public FormatterStep create() {
6464

6565
private State createState() {
6666
String instructions = "https://docs.buf.build/installation";
67-
ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
67+
ForeignExe exe = ForeignExe.nameAndVersion("buf", version)
6868
.pathToExe(pathToExe)
6969
.versionRegex(Pattern.compile("(\\S*)"))
7070
.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
71-
return new State(this, exeAbsPath);
71+
return new State(this, exe);
7272
}
7373

7474
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
@@ -77,22 +77,21 @@ static class State implements Serializable {
7777
// used for up-to-date checks and caching
7878
final String version;
7979
final transient ForeignExe exe;
80-
// used for executing
81-
private transient @Nullable List<String> args;
8280

83-
State(BufStep step, ForeignExe exeAbsPath) {
81+
State(BufStep step, ForeignExe exe) {
8482
this.version = step.version;
85-
this.exe = Objects.requireNonNull(exeAbsPath);
83+
this.exe = Objects.requireNonNull(exe);
8684
}
8785

8886
String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
89-
if (args == null) {
90-
args = Arrays.asList(
91-
exe.confirmVersionAndGetAbsolutePath(),
92-
"format",
93-
file.getAbsolutePath());
94-
}
95-
return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8);
87+
return runner.exec(
88+
input.getBytes(StandardCharsets.UTF_8),
89+
List.of(
90+
exe.confirmVersionAndGetAbsolutePath(),
91+
"format",
92+
file.getAbsolutePath()
93+
)
94+
).assertExitZero(StandardCharsets.UTF_8);
9695
}
9796

9897
FormatterFunc.Closeable toFunc() {

0 commit comments

Comments
 (0)