From 4b2be4c368c211860f89cb7e8472558576fdc04f Mon Sep 17 00:00:00 2001 From: jcater Date: Fri, 7 Jul 2017 12:53:56 -0400 Subject: Fix BuildRuleWithDefaultsBuilder to work properly with NODEP_LABEL attributes. NODEP_LABEL attributes are not allowed to set file types, but populateLabelAttributes assumes that every label attribute has a file type set. Fix this by adding in better checks. PiperOrigin-RevId: 161212141 --- .../build/lib/testutil/BuildRuleWithDefaultsBuilder.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/test/java/com/google/devtools') diff --git a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java index e0e6b77407..183ff66c7d 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java @@ -24,7 +24,6 @@ import com.google.devtools.build.lib.syntax.Type.LabelClass; import com.google.devtools.build.lib.syntax.Type.ListType; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.util.Preconditions; - import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -96,13 +95,16 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder { String label = null; if (attribute.getAllowedFileTypesPredicate() != FileTypeSet.NO_FILE) { // Try to populate with files first - String extension = null; + String extension = ""; if (attribute.getAllowedFileTypesPredicate() == FileTypeSet.ANY_FILE) { extension = ".txt"; - } else { + } else if (attribute.getAllowedFileTypesPredicate() != null) { FileTypeSet fileTypes = attribute.getAllowedFileTypesPredicate(); // This argument should always hold, if not that means a Blaze design/implementation error - Preconditions.checkArgument(!fileTypes.getExtensions().isEmpty()); + Preconditions.checkArgument( + !fileTypes.getExtensions().isEmpty(), + "Attribute %s does not have any allowed file types", + attribute.getName()); extension = fileTypes.getExtensions().get(0); } label = getDummyFileLabel(rulePkg, filePkg, extension, attrType); -- cgit v1.2.3