Skip to content

Commit

Permalink
Fix NPE in NonconfigurableAttributeMapper
Browse files Browse the repository at this point in the history
    This PR fixes: bazelbuild/bazel#2036 to provide more error message

    Explanation why this works: see PR comment thread starting here: bazelbuild/bazel#2531 (comment)

    without the fix:
    ```
    java.lang.RuntimeException: Unrecoverable error while evaluating node 'CONFIGURED_TARGET:@grpc//:grpc++_config_proto 05cc524e2c4b9309660fb7daa4e35db9 (1333167441 455593757)' (requested by nodes 'CONFIGURED_TARGET:@grpc//:grpc_plugin_support 05cc524e2c4b9309660fb7daa4e35db9 (136418248 455593757)')
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:429)
            at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:501)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.NullPointerException
            at com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.get(NonconfigurableAttributeMapper.java:45)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.isTestOnlyRule(BazelRuleClassProvider.java:268)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validateDirectPrerequisiteForTestOnly(BazelRuleClassProvider.java:254)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validate(BazelRuleClassProvider.java:190)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.validateDirectPrerequisite(RuleContext.java:1937)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.createTargetMap(RuleContext.java:1610)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.build(RuleContext.java:1449)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:241)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:171)
            at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:491)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:1024)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:249)
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:370)
            ... 4 more
    java.lang.RuntimeException: Unrecoverable error while evaluating node 'CONFIGURED_TARGET:@grpc//:grpc++_config_proto 05cc524e2c4b9309660fb7daa4e35db9 (1333167441 455593757)' (requested by nodes 'CONFIGURED_TARGET:@grpc//:grpc_plugin_support 05cc524e2c4b9309660fb7daa4e35db9 (136418248 455593757)')
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:429)
            at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:501)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.NullPointerException
            at com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.get(NonconfigurableAttributeMapper.java:45)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.isTestOnlyRule(BazelRuleClassProvider.java:268)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validateDirectPrerequisiteForTestOnly(BazelRuleClassProvider.java:254)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validate(BazelRuleClassProvider.java:190)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.validateDirectPrerequisite(RuleContext.java:1937)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.createTargetMap(RuleContext.java:1610)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.build(RuleContext.java:1449)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:241)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:171)
            at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:491)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:1024)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:249)
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:370)
            ... 4 more
    ```

    with this fix:
    ```
    java.lang.RuntimeException: Unrecoverable error while evaluating node 'CONFIGURED_TARGET:@grpc//:grpc++_config_proto 26809c5247f58eb7a6314bd0e13655a1 (1551360347 275342100)' (requested by nodes 'CONFIGURED_TARGET:@grpc//:grpc_plugin_support 26809c5247f58eb7a6314bd0e13655a1 (859246773 275342100)')
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:438)
            at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:501)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalArgumentException: No such attribute testonly in rule protobuf_archive
            at com.google.devtools.build.lib.packages.AbstractAttributeMapper.getIndexWithTypeCheck(AbstractAttributeMapper.java:228)
            at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:57)
            at com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.get(NonconfigurableAttributeMapper.java:45)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.isTestOnlyRule(BazelRuleClassProvider.java:266)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validateDirectPrerequisiteForTestOnly(BazelRuleClassProvider.java:252)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validate(BazelRuleClassProvider.java:196)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.validateDirectPrerequisite(RuleContext.java:1954)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.createTargetMap(RuleContext.java:1626)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.build(RuleContext.java:1465)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:245)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:176)
            at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:491)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:1094)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:251)
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:373)
            ... 4 more
    java.lang.RuntimeException: Unrecoverable error while evaluating node 'CONFIGURED_TARGET:@grpc//:grpc++_config_proto 26809c5247f58eb7a6314bd0e13655a1 (1551360347 275342100)' (requested by nodes 'CONFIGURED_TARGET:@grpc//:grpc_plugin_support 26809c5247f58eb7a6314bd0e13655a1 (859246773 275342100)')
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:438)
            at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:501)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalArgumentException: No such attribute testonly in rule protobuf_archive
            at com.google.devtools.build.lib.packages.AbstractAttributeMapper.getIndexWithTypeCheck(AbstractAttributeMapper.java:228)
            at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:57)
            at com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.get(NonconfigurableAttributeMapper.java:45)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.isTestOnlyRule(BazelRuleClassProvider.java:266)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validateDirectPrerequisiteForTestOnly(BazelRuleClassProvider.java:252)
            at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider$BazelPrerequisiteValidator.validate(BazelRuleClassProvider.java:196)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.validateDirectPrerequisite(RuleContext.java:1954)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.createTargetMap(RuleContext.java:1626)
            at com.google.devtools.build.lib.analysis.RuleContext$Builder.build(RuleContext.java:1465)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:245)
            at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:176)
            at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:491)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:1094)
            at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:251)
            at com.google.devtools.build.skyframe.ParallelEvaluator$Evaluate.run(ParallelEvaluator.java:373)
            ... 4 more
    ```

    Closes #2531.

    --
    Reviewed-on: bazelbuild/bazel#2531
    PiperOrigin-RevId: 147814996
    MOS_MIGRATED_REVID=147814996
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent fd89941 commit e068abe
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.packages;

import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.util.Preconditions;

/**
* {@link AttributeMap} implementation that triggers an {@link IllegalStateException} if called
Expand All @@ -25,7 +25,8 @@
*/
public class NonconfigurableAttributeMapper extends AbstractAttributeMapper {
private NonconfigurableAttributeMapper(Rule rule) {
super(rule);
super(rule.getPackage(), rule.getRuleClassObject(), rule.getLabel(),
rule.getAttributeContainer());
}

/**
Expand All @@ -40,7 +41,7 @@ public static NonconfigurableAttributeMapper of (Rule rule) {
}

@Override
public <T> T get(String attributeName, com.google.devtools.build.lib.packages.Type<T> type) {
public <T> T get(String attributeName, com.google.devtools.build.lib.syntax.Type<T> type) {
T attr = super.get(attributeName, type);
Preconditions.checkState(!getAttributeDefinition(attributeName).isConfigurable(),
"Attribute '%s' is potentially configurable - not allowed here", attributeName);
Expand Down

0 comments on commit e068abe

Please sign in to comment.