Skip to content

Commit

Permalink
Prepare for stricter nullness stub for Files.createDirectories.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 537332469
  • Loading branch information
cpovirk authored and Javac Team committed Jun 2, 2023
1 parent 0902ef6 commit ca998fa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions java/com/google/turbine/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -207,7 +208,11 @@ public static Result compile(TurbineOptions options) throws IOException {
DepsProto.Dependencies deps =
Dependencies.collectDeps(options.targetLabel(), bootclasspath, bound, lowered);
Path path = Paths.get(options.outputDeps().get());
Files.createDirectories(path.getParent());
/*
* TODO: cpovirk - Consider checking outputDeps for validity earlier so that anyone who
* `--output_deps=/` or similar will get a proper error instead of NPE.
*/
Files.createDirectories(requireNonNull(path.getParent()));
try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(path))) {
deps.writeTo(os);
}
Expand Down Expand Up @@ -355,7 +360,8 @@ private static void writeSources(
if (Files.isDirectory(path)) {
for (SourceFile source : generatedSources.values()) {
Path to = path.resolve(source.path());
Files.createDirectories(to.getParent());
// TODO: cpovirk - Consider checking gensrcOutput, similar to outputDeps.
Files.createDirectories(requireNonNull(to.getParent()));
Files.writeString(to, source.source());
}
return;
Expand All @@ -380,7 +386,8 @@ private static void writeResources(
if (Files.isDirectory(path)) {
for (Map.Entry<String, byte[]> resource : generatedResources.entrySet()) {
Path to = path.resolve(resource.getKey());
Files.createDirectories(to.getParent());
// TODO: cpovirk - Consider checking resourceOutput, similar to outputDeps.
Files.createDirectories(requireNonNull(to.getParent()));
Files.write(to, resource.getValue());
}
return;
Expand Down

0 comments on commit ca998fa

Please sign in to comment.