diff options
author | 2016-06-15 19:06:56 +0000 | |
---|---|---|
committer | 2016-06-16 09:01:39 +0000 | |
commit | 19f2238b608d7ebba182a2bdd405e4696975f733 (patch) | |
tree | 6cbadb8aee4179e29f7b55be4a26cf6890b2196e /src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java | |
parent | cedd8d18afc42d328153056470024a1bd98c5310 (diff) |
Fix hypothetical crash bug in AspectDefinition#addAllAttributesOfAspect when the default value of a parameterized aspect attribute is null. This is hypothetical because I couldn't figure out an end-to-end way to tickle the bug. Still, the surrounding code is very brittle and things may change in the future such that the bug is trivially tickle-able.
--
MOS_MIGRATED_REVID=124977450
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java index 606b17774d..20c2a6ab28 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.util.Preconditions; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -178,6 +179,11 @@ public final class AspectDefinition { return classStrings.build(); } + @Nullable + private static Label maybeGetRepositoryRelativeLabel(Rule from, @Nullable Label label) { + return label == null ? null : from.getLabel().resolveRepositoryRelative(label); + } + /** * Collects all attribute labels from the specified aspectDefinition. */ @@ -192,14 +198,21 @@ public final class AspectDefinition { continue; } if (aspectAttribute.getType() == BuildType.LABEL) { - Label label = from.getLabel().resolveRepositoryRelative( - BuildType.LABEL.cast(aspectAttribute.getDefaultValue(from))); + Label label = maybeGetRepositoryRelativeLabel( + from, BuildType.LABEL.cast(aspectAttribute.getDefaultValue(from))); if (label != null) { labelBuilder.put(aspectAttribute, label); } } else if (aspectAttribute.getType() == BuildType.LABEL_LIST) { - for (Label label : BuildType.LABEL_LIST.cast(aspectAttribute.getDefaultValue(from))) { - labelBuilder.put(aspectAttribute, from.getLabel().resolveRepositoryRelative(label)); + List<Label> defaultLabels = BuildType.LABEL_LIST.cast( + aspectAttribute.getDefaultValue(from)); + if (defaultLabels != null) { + for (Label defaultLabel : defaultLabels) { + Label label = maybeGetRepositoryRelativeLabel(from, defaultLabel); + if (label != null) { + labelBuilder.put(aspectAttribute, label); + } + } } } } |