aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-11-09 20:20:13 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-10 09:21:48 +0000
commitf83f70ed3921b5ed347f063b593eae36f6d950f3 (patch)
tree888ace643c8fd1aaec7b6b8333f8f15a163edeaa /src/main/java/com/google/devtools
parentc88bc9fe8f744689a98e269a0f8a6b3d51f22678 (diff)
Fix NPE when maven_jar sha1 isn't set and caching is enabled
-- MOS_MIGRATED_REVID=138669967
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java
index 595e0cb991..64cdfdf14a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java
@@ -30,32 +30,33 @@ import javax.annotation.Nullable;
public class RepositoryCache {
/** The types of cache keys used. */
- public static enum KeyType {
+ public enum KeyType {
SHA1("SHA-1", "\\p{XDigit}{40}", "sha1", Hashing.sha1()),
SHA256("SHA-256", "\\p{XDigit}{64}", "sha256", Hashing.sha256());
private final String stringRepr;
private final String regexp;
- private final String cacheDirName;
+ private final String hashName;
+ @SuppressWarnings("ImmutableEnumChecker")
private final HashFunction hashFunction;
- KeyType(String stringRepr, String regexp, String cacheDirName, HashFunction hashFunction) {
+ KeyType(String stringRepr, String regexp, String hashName, HashFunction hashFunction) {
this.stringRepr = stringRepr;
this.regexp = regexp;
- this.cacheDirName = cacheDirName;
+ this.hashName = hashName;
this.hashFunction = hashFunction;
}
- public boolean isValid(String checksum) {
- return checksum.matches(regexp);
+ public boolean isValid(@Nullable String checksum) {
+ return checksum != null && checksum.matches(regexp);
}
- public String getDirectoryName() {
- return cacheDirName;
+ public Path getCachePath(Path parentDirectory) {
+ return parentDirectory.getChild(hashName);
}
- public Path getCachePath(Path parentDirectory) {
- return parentDirectory.getChild(cacheDirName);
+ public Hasher newHasher() {
+ return hashFunction.newHasher();
}
@Override
@@ -205,7 +206,7 @@ public class RepositoryCache {
* @throws IOException
*/
public static String getChecksum(KeyType keyType, Path path) throws IOException {
- Hasher hasher = keyType.hashFunction.newHasher();
+ Hasher hasher = keyType.newHasher();
byte[] byteBuffer = new byte[BUFFER_SIZE];
try (InputStream stream = path.getInputStream()) {
int numBytesRead = stream.read(byteBuffer);