Skip to content

NPE when creating a repository rule in a macro  #21451

@blorente

Description

@blorente

Description of the bug:

Starting from 8.0.0-pre.20240206.3 (more precisely this commit), I get an NPE when I try to execute a repository rule that I create in a macro.

The error message:

➜ bazel clean --expunge ; USE_BAZEL_VERSION=rolling bazel build ...
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@@constants' (requested by nodes 'PACKAGE_LOOKUP:@@constants//')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:551)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.NullPointerException
        at com.google.common.collect.AbstractTable.putAll(AbstractTable.java:113)
        at com.google.common.collect.HashBasedTable.putAll(HashBasedTable.java:49)
        at com.google.devtools.build.lib.cmdline.Label$RepoMappingRecorder.mergeEntries(Label.java:237)
        at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryFunction.fetchInternal(StarlarkRepositoryFunction.java:245)
        at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryFunction.fetch(StarlarkRepositoryFunction.java:150)
        at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.fetchRepository(RepositoryDelegatorFunction.java:423)
        at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:208)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:462)
        ... 7 more

I suspect the solution is to add a null check to this code should have a null check (as the entries we get as a parameter is declared @Nullable in the relevant constructor), but I'm not confident enough in the codebase to know if this signifies a deeper issue.

Which category does this issue belong to?

Rules API

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Minimal example repository is https://github.com/blorente/repro-bazel-npe-feb-2024
After cloning, the issue should reproduce when running USE_BAZEL_VERSION=rolling bazel build //...

Which operating system are you running Bazel on?

macOS, for the purposes of this issue.

What is the output of bazel info release?

I've seen it starting with 8.0.0-pre.20240206.3

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

The bug was introduced in 9edaddd

Have you found anything relevant by searching the web?

Nothing on the issues in this repository.

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

Labels

P1I'll work on this now. (Assignee required)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions