diff --git a/src/main/java/com/google/testing/compile/Compilation.java b/src/main/java/com/google/testing/compile/Compilation.java index b00dc93d..57342b41 100644 --- a/src/main/java/com/google/testing/compile/Compilation.java +++ b/src/main/java/com/google/testing/compile/Compilation.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.testing.compile.JavaFileObjects.asByteSource; +import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import static javax.tools.Diagnostic.Kind.ERROR; @@ -155,9 +156,8 @@ public Optional generatedFile(Location location, String path) { // We're relying on the implementation of location.getName() to be equivalent to the first // part of the path. String expectedFilename = String.format("%s/%s", location.getName(), path); - return generatedFiles() - .stream() - .filter(generated -> generated.toUri().getPath().endsWith(expectedFilename)) + return generatedFiles().stream() + .filter(generated -> requireNonNull(generated.toUri().getPath()).endsWith(expectedFilename)) .findFirst(); } diff --git a/src/main/java/com/google/testing/compile/CompilationSubject.java b/src/main/java/com/google/testing/compile/CompilationSubject.java index d8adad70..2fd3f393 100644 --- a/src/main/java/com/google/testing/compile/CompilationSubject.java +++ b/src/main/java/com/google/testing/compile/CompilationSubject.java @@ -26,6 +26,7 @@ import static com.google.testing.compile.Compilation.Status.SUCCESS; import static com.google.testing.compile.JavaFileObjectSubject.javaFileObjects; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; @@ -338,7 +339,7 @@ private JavaFileObjectSubject checkGeneratedFile( facts.add(fact("in location", location.getName())); facts.add(simpleFact("it generated:")); for (JavaFileObject generated : actualNotNull().generatedFiles()) { - if (generated.toUri().getPath().contains(location.getName())) { + if (requireNonNull(generated.toUri().getPath()).contains(location.getName())) { facts.add(simpleFact(" " + generated.toUri().getPath())); } } @@ -421,7 +422,8 @@ private ImmutableList> findDiagnosticsInFil filterDiagnostics( diagnostic -> { JavaFileObject source = diagnostic.getSource(); - return source != null && source.toUri().getPath().equals(expectedFilePath); + return source != null + && requireNonNull(source.toUri().getPath()).equals(expectedFilePath); }); if (diagnosticsInFile.isEmpty()) { failExpectingMatchingDiagnostic( diff --git a/src/main/java/com/google/testing/compile/InMemoryJavaFileManager.java b/src/main/java/com/google/testing/compile/InMemoryJavaFileManager.java index c50e7817..d7f540a2 100644 --- a/src/main/java/com/google/testing/compile/InMemoryJavaFileManager.java +++ b/src/main/java/com/google/testing/compile/InMemoryJavaFileManager.java @@ -16,6 +16,7 @@ package com.google.testing.compile; import static com.google.common.collect.MoreCollectors.toOptional; +import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; import com.google.common.cache.CacheBuilder; @@ -129,7 +130,7 @@ private Optional findInMemoryInput(String packageName, String re String suffix = packageName.isEmpty() ? relativeName : packageName.replace('.', '/') + "/" + relativeName; return inMemoryInputs.entrySet().stream() - .filter(entry -> entry.getKey().getPath().endsWith(suffix)) + .filter(entry -> requireNonNull(entry.getKey().getPath()).endsWith(suffix)) .map(Map.Entry::getValue) .collect(toOptional()); // Might have problems if more than one input file matches. } @@ -151,7 +152,8 @@ public JavaFileObject getJavaFileForOutput(Location location, String className, ImmutableList getGeneratedSources() { ImmutableList.Builder result = ImmutableList.builder(); for (Map.Entry entry : inMemoryOutputs.asMap().entrySet()) { - if (entry.getKey().getPath().startsWith("/" + StandardLocation.SOURCE_OUTPUT.name()) + if (requireNonNull(entry.getKey().getPath()) + .startsWith("/" + StandardLocation.SOURCE_OUTPUT.name()) && (entry.getValue().getKind() == Kind.SOURCE)) { result.add(entry.getValue()); } diff --git a/src/main/java/com/google/testing/compile/JavaFileObjectSubject.java b/src/main/java/com/google/testing/compile/JavaFileObjectSubject.java index 7f8da2dd..29211b6f 100644 --- a/src/main/java/com/google/testing/compile/JavaFileObjectSubject.java +++ b/src/main/java/com/google/testing/compile/JavaFileObjectSubject.java @@ -23,6 +23,7 @@ import static com.google.testing.compile.TreeDiffer.diffCompilationUnits; import static com.google.testing.compile.TreeDiffer.matchCompilationUnits; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableList; import com.google.common.io.ByteSource; @@ -62,7 +63,7 @@ public static JavaFileObjectSubject assertThat(@Nullable JavaFileObject actual) @Override protected String actualCustomStringRepresentation() { - return actualNotNull().toUri().getPath(); + return requireNonNull(actualNotNull().toUri().getPath()); } /** diff --git a/src/main/java/com/google/testing/compile/JavaFileObjects.java b/src/main/java/com/google/testing/compile/JavaFileObjects.java index 81900c32..174bd1e5 100644 --- a/src/main/java/com/google/testing/compile/JavaFileObjects.java +++ b/src/main/java/com/google/testing/compile/JavaFileObjects.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import static javax.tools.JavaFileObject.Kind.SOURCE; import com.google.common.base.CharMatcher; @@ -162,7 +163,7 @@ public static JavaFileObject forResource(String resourceName) { } static Kind deduceKind(URI uri) { - String path = uri.getPath(); + String path = requireNonNull(uri.getPath()); for (Kind kind : Kind.values()) { if (path.endsWith(kind.extension)) { return kind;