Skip to content

Commit b47177d

Browse files
committed
Fix static analysis
1 parent 0fa20a1 commit b47177d

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

src/main/java/build/buildfarm/worker/persistent/FileAccessUtils.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
import java.util.logging.Logger;
1212

1313
// Utility for concurrent move/copy/link of files
14-
public class FileAccessUtils {
14+
public final class FileAccessUtils {
15+
// singleton class with only static methods
16+
private FileAccessUtils() {}
17+
1518
private static final Logger logger = Logger.getLogger(FileAccessUtils.class.getName());
1619

17-
private static final ConcurrentHashMap<Path, EasyMonitor> fileLocks = new ConcurrentHashMap<>();
20+
private static final ConcurrentHashMap<Path, PathLock> fileLocks = new ConcurrentHashMap<>();
1821

1922
// Used here for locking "files"
20-
private static class EasyMonitor {
21-
public EasyMonitor() {}
23+
private static class PathLock {
24+
// Not used elsewhere
25+
private PathLock() {}
2226
}
2327

2428
/**
@@ -130,7 +134,7 @@ public static void linkFile(Path from, Path to) throws IOException {
130134
*/
131135
public static void deleteFileIfExists(Path toDelete) throws IOException {
132136
Path absTo = toDelete.toAbsolutePath();
133-
EasyMonitor toLock = fileLock(absTo);
137+
PathLock toLock = fileLock(absTo);
134138
synchronized (toLock) {
135139
try {
136140
Files.deleteIfExists(absTo);
@@ -148,7 +152,7 @@ public static void deleteFileIfExists(Path toDelete) throws IOException {
148152
* <p>It is up to the write operation to specify whether or not to overwrite existing files.
149153
*/
150154
private static IOException writeFileSafe(Path absTo, Supplier<IOException> writeOp) {
151-
EasyMonitor toLock = fileLock(absTo);
155+
PathLock toLock = fileLock(absTo);
152156
synchronized (toLock) {
153157
try {
154158
// If 'absTo' is a symlink, checks if its target file exists
@@ -164,7 +168,7 @@ private static IOException writeFileSafe(Path absTo, Supplier<IOException> write
164168
}
165169

166170
// "Logical" file lock
167-
private static EasyMonitor fileLock(Path writeTo) {
168-
return fileLocks.computeIfAbsent(writeTo, k -> new EasyMonitor());
171+
private static PathLock fileLock(Path writeTo) {
172+
return fileLocks.computeIfAbsent(writeTo, k -> new PathLock());
169173
}
170174
}

src/main/java/build/buildfarm/worker/persistent/ProtoCoordinator.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public PersistentWorker create(WorkerKey workerKey) throws Exception {
7373
StringBuilder initArgs = new StringBuilder();
7474
for (String s : workerKey.getCmd()) {
7575
initArgs.append(s);
76-
initArgs.append("\n");
76+
initArgs.append('\n');
7777
}
7878
for (String s : workerKey.getArgs()) {
7979
initArgs.append(s);
80-
initArgs.append("\n");
80+
initArgs.append('\n');
8181
}
8282

8383
Files.write(initArgsLogFile, initArgs.toString().getBytes());
@@ -178,17 +178,16 @@ public ResponseCtx postWorkCleanup(
178178
private IOException logBadCleanup(RequestCtx request, IOException e) {
179179
WorkFilesContext context = request.filesContext;
180180

181-
StringBuilder sb = new StringBuilder();
182-
sb.append(
183-
"Output files failure debug for request with args<"
184-
+ request.request.getArgumentsList()
185-
+ ">:\n");
186-
sb.append("getOutputPathsList:\n");
187-
sb.append(context.outputPaths);
188-
sb.append("getOutputFilesList:\n");
189-
sb.append(context.outputFiles);
190-
sb.append("getOutputDirectoriesList:\n");
191-
sb.append(context.outputDirectories);
181+
StringBuilder sb = new StringBuilder(122);
182+
sb.append("Output files failure debug for request with args<")
183+
.append(request.request.getArgumentsList())
184+
.append(">:\ngetOutputPathsList:\n")
185+
.append(context.outputPaths)
186+
.append("getOutputFilesList:\n")
187+
.append(context.outputFiles)
188+
.append("getOutputDirectoriesList:\n")
189+
.append(context.outputDirectories);
190+
192191
logger.severe(sb.toString());
193192

194193
e.printStackTrace();

src/main/java/build/buildfarm/worker/persistent/WorkerInputs.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import com.google.protobuf.ByteString;
77
import java.io.IOException;
88
import java.nio.file.Path;
9-
import java.nio.file.Paths;
10-
import java.util.ArrayList;
119
import java.util.List;
1210
import java.util.logging.Logger;
13-
import persistent.common.util.Args;
1411

1512
public class WorkerInputs {
1613
private static final Logger logger = Logger.getLogger(WorkerInputs.class.getName());
@@ -114,17 +111,4 @@ public static WorkerInputs from(WorkFilesContext workFilesContext, List<String>
114111

115112
return new WorkerInputs(workFilesContext.opRoot, absToolInputs, toolInputs, pathInputs);
116113
}
117-
118-
private static List<Path> argsFiles(Path opRoot, List<String> reqArgs) {
119-
List<Path> files = new ArrayList<>();
120-
for (String a : reqArgs) {
121-
if (Args.isArgsFile(a)) {
122-
try {
123-
files.add(opRoot.resolve(Paths.get(a.substring(1))));
124-
} catch (Exception ignored) {
125-
}
126-
}
127-
}
128-
return files;
129-
}
130114
}

0 commit comments

Comments
 (0)