Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in implicit output pattern "%{x}" when x is a "zero" label attribute #5581

Open
pcj opened this issue Jul 12, 2018 · 4 comments
Open

NPE in implicit output pattern "%{x}" when x is a "zero" label attribute #5581

pcj opened this issue Jul 12, 2018 · 4 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug

Comments

@pcj
Copy link
Member

pcj commented Jul 12, 2018

Attempting to use a sass_binary() rule, observing this error with 0.14.1, 0.15.0:

Minimal repo example (for me) is the presence of any sass_binary rule in a BUILD file where the rule is missing the mandatory argument src:

http_archive(
    name = "build_bazel_rules_nodejs",
    url = "https://github.com/bazelbuild/rules_nodejs/archive/0.10.0.zip",
    strip_prefix = "rules_nodejs-0.10.0",
    sha256 = "2f77623311da8b5009b1c7eade12de8e15fa3cd2adf9dfcc9f87cb2082b2211f",
)
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
node_repositories(package_json = [])

http_archive(
    name = "io_bazel_rules_sass",
    url = "https://github.com/bazelbuild/rules_sass/archive/24331cf9a598c13089c9f441ef7fd9df23654b6f.zip",
    strip_prefix = "rules_sass-24331cf9a598c13089c9f441ef7fd9df23654b6f",
    sha256 = "deb3c4c5ae3f35ca11ace945ba481a77ec1d05fb9bebced1bb6dd41f6e70cb4b",
)
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
sass_repositories()
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")

sass_binary(
    name = "foo",
)

I tried to trace it back manually to see where the "rule" attribute map could be null, didn't think it could be. Maybe it's something about sass_binary is defnining outputs? https://github.com/bazelbuild/rules_sass/blob/master/sass/sass.bzl#L124

Caused by: java.lang.NullPointerException
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction.attributeValues(ImplicitOutputsFunction.java:408)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction.access$000(ImplicitOutputsFunction.java:63)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction$1.get(ImplicitOutputsFunction.java:207)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction$ParsedTemplate.substituteAttributes(ImplicitOutputsFunction.java:504)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction.substitutePlaceholderIntoTemplate(ImplicitOutputsFunction.java:534)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction.substitutePlaceholderIntoTemplate(ImplicitOutputsFunction.java:475)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction$TemplateImplicitOutputsFunction.getImplicitOutputs(ImplicitOutputsFunction.java:268)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction$SkylarkImplicitOutputsFunctionWithCallback.calculateOutputs(ImplicitOutputsFunction.java:124)
	at com.google.devtools.build.lib.packages.ImplicitOutputsFunction$SkylarkImplicitOutputsFunction.getImplicitOutputs(ImplicitOutputsFunction.java:76)
	at com.google.devtools.build.lib.packages.Rule.populateImplicitOutputFiles(Rule.java:551)
	at com.google.devtools.build.lib.packages.Rule.populateOutputFilesInternal(Rule.java:495)
	at com.google.devtools.build.lib.packages.Rule.populateOutputFiles(Rule.java:475)
	at com.google.devtools.build.lib.packages.RuleClass.createRule(RuleClass.java:1611)
	at com.google.devtools.build.lib.packages.RuleFactory.createRule(RuleFactory.java:131)
	at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:177)
	at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:218)
	at com.google.devtools.build.lib.analysis.skylark.SkylarkRuleClassFunctions$SkylarkRuleFunction.call(SkylarkRuleClassFunctions.java:615)
	at com.google.devtools.build.lib.syntax.BaseFunction.callWithArgArray(BaseFunction.java:462)
	at com.google.devtools.build.lib.syntax.BaseFunction.call(BaseFunction.java:440)
	at com.google.devtools.build.lib.syntax.FuncallExpression.callFunction(FuncallExpression.java:1003)
	at com.google.devtools.build.lib.syntax.FuncallExpression.doEval(FuncallExpression.java:975)
	at com.google.devtools.build.lib.syntax.Expression.eval(Expression.java:69)
	at com.google.devtools.build.lib.syntax.Eval.execDispatch(Eval.java:201)
	at com.google.devtools.build.lib.syntax.Eval.exec(Eval.java:183)
	at com.google.devtools.build.lib.syntax.BuildFileAST.execTopLevelStatement(BuildFileAST.java:237)
	at com.google.devtools.build.lib.syntax.BuildFileAST.doExec(BuildFileAST.java:210)
	at com.google.devtools.build.lib.syntax.BuildFileAST.lambda$exec$1(BuildFileAST.java:200)
	at com.google.devtools.build.lib.syntax.DebugServerUtils.runWithDebuggingIfEnabled(DebugServerUtils.java:62)
	at com.google.devtools.build.lib.syntax.BuildFileAST.exec(BuildFileAST.java:199)
	at com.google.devtools.build.lib.packages.PackageFactory.evaluateBuildFile(PackageFactory.java:1650)
	at com.google.devtools.build.lib.packages.PackageFactory.createPackageFromAst(PackageFactory.java:1289)
	at com.google.devtools.build.lib.skyframe.PackageFunction.loadPackage(PackageFunction.java:1233)
	at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:475)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:382)

Adding a valid src attribute recovers bazel from the NPE, restoring expected/normal behaviour:

sass_binary(
    name = "foo",
    src = "main.scss",
)

@laurentlb
Copy link
Contributor

Repro:

sass.bzl

def _sass_binary_impl(ctx): pass

sass_binary = rule(
    implementation = _sass_binary_impl,
    attrs = {
        "src": attr.label(
            mandatory = True,
            single_file = True,
        ),
    },
    outputs = {"x": "%{src}.css"},
)

BUILD

load(":sass.bzl", "sass_binary")

sass_binary(
    name = "foo",
    # src = "main.scss",
)

bazel build --nobuild :foo

@laurentlb laurentlb changed the title NPE while parsing sass_binary rule NPE in implicit output pattern "%{x}" when x is a "zero" label attribute Jul 23, 2018
@laurentlb laurentlb added P1 I'll work on this now. (Assignee required) team-Starlark and removed category: extensibility > skylark labels Nov 21, 2018
@laurentlb laurentlb removed their assignment Nov 21, 2018
@laurentlb
Copy link
Contributor

There's a proposal to remove this feature (https://docs.google.com/document/d/14A9HK8Jn2jErMayLEE3nrNJIxNfZWN_slFbhgtS6-aM/edit).

@katre
Copy link
Member

katre commented May 13, 2020

Downgrading and sending for re-triage.

@katre katre added untriaged and removed P1 I'll work on this now. (Assignee required) labels May 13, 2020
@laurentlb laurentlb added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels May 13, 2020
@brandjon
Copy link
Member

Sounds similar to #2766.

@brandjon brandjon added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Build-Language and removed P2 We'll consider working on this in future. (Assignee optional) team-Starlark labels Feb 16, 2021
@brandjon brandjon added untriaged team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Build-Language labels Nov 4, 2022
@comius comius added P2 We'll consider working on this in future. (Assignee optional) and removed P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) untriaged labels Aug 22, 2023
@comius comius self-assigned this Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug
Projects
None yet
Development

No branches or pull requests

7 participants