diff options
author | 2016-07-20 14:55:53 +0000 | |
---|---|---|
committer | 2016-07-20 15:02:10 +0000 | |
commit | 2479405822a955d009ad5f4e170391a75f5e33c5 (patch) | |
tree | 3240735e4534dc0052f043fdd6a9887346cb8671 /src | |
parent | b47f344508faa2d2ba8dc93a58546c0ebe9d6584 (diff) |
Fix NPE with unset maven_jar sha1
Fixes #1537.
--
MOS_MIGRATED_REVID=127945452
Diffstat (limited to 'src')
3 files changed, 17 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java index 8e2693b4ad..28c4a00dcc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java @@ -180,8 +180,9 @@ public class MavenJarFunction extends HttpArchiveFunction { this.outputDirectory = outputDirectory; this.artifact = mapper.get("artifact", Type.STRING); - this.sha1 = (mapper.has("sha1", Type.STRING)) ? mapper.get("sha1", Type.STRING) : null; - if (!sha1.matches("\\p{XDigit}{40}")) { + this.sha1 = mapper.isAttributeValueExplicitlySpecified("sha1") + ? mapper.get("sha1", Type.STRING) : null; + if (sha1 != null && !sha1.matches("\\p{XDigit}{40}")) { throw new IOException("Invalid SHA-1 for maven_jar " + name + ": '" + sha1 + "'"); } this.url = serverValue.getUrl(); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java index 916546330d..6ad732e9d7 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java @@ -65,4 +65,15 @@ public class MavenJarFunctionTest extends BuildViewTestCase { AggregatingAttributeMapper map = AggregatingAttributeMapper.of(rule); new MavenDownloader("foo", map, scratch.dir("/whatever"), TEST_SERVER); } + + @Test + public void testNoSha1() throws Exception { + Rule rule = scratchRule("external", "foo", + "maven_jar(", + " name = 'foo',", + " artifact = 'x',", + ")"); + AggregatingAttributeMapper map = AggregatingAttributeMapper.of(rule); + new MavenDownloader("foo", map, scratch.dir("/whatever"), TEST_SERVER); + } } diff --git a/src/test/shell/bazel/maven_test.sh b/src/test/shell/bazel/maven_test.sh index 48d60f36fb..c3d9293a33 100755 --- a/src/test/shell/bazel/maven_test.sh +++ b/src/test/shell/bazel/maven_test.sh @@ -114,19 +114,20 @@ function test_maven_jar_mismatched_sha1() { setup_zoo serve_jar + wrong_sha1="0123456789012345678901234567890123456789" cat > WORKSPACE <<EOF maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:1.23", repository = 'http://localhost:$nc_port/', - sha1 = '$sha256', + sha1 = '$wrong_sha1', ) bind(name = 'mongoose', actual = '@endangered//jar') EOF bazel fetch //zoo:ball-pit >& $TEST_log && echo "Expected fetch to fail" kill_nc - expect_log "has SHA-1 of $sha1, does not match expected SHA-1 ($sha256)" + expect_log "has SHA-1 of $sha1, does not match expected SHA-1 ($wrong_sha1)" } function test_default_repository() { |