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 when creating a repository rule in a macro #21451

Closed
blorente opened this issue Feb 21, 2024 · 4 comments
Closed

NPE when creating a repository rule in a macro #21451

blorente opened this issue Feb 21, 2024 · 4 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@blorente
Copy link

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

@github-actions github-actions bot added the team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts label Feb 21, 2024
@fmeum
Copy link
Collaborator

fmeum commented Feb 21, 2024

@bazel-io fork 7.1.0

@fmeum
Copy link
Collaborator

fmeum commented Feb 21, 2024

Cc @Wyverald

@Wyverald Wyverald changed the title [8.0.0-pre.20240206.3] NPE when creating a repository rule in a macro NPE when creating a repository rule in a macro Feb 21, 2024
@Wyverald Wyverald added P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. and removed untriaged team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts labels Feb 21, 2024
@Wyverald
Copy link
Member

Thanks for the report! A fix is in flight.

bazel-io pushed a commit to bazel-io/bazel that referenced this issue Feb 21, 2024
… WORKSPACE repo rules

Follow-up to bazelbuild@1cbf09d; beyond not recording those entries in the marker file, we shouldn't even record them in memory in the first place. This avoids nasty problems with unexported repo rules (gah) and should be an extremely tiny performance win as a bonus...

Fixes bazelbuild#21451

PiperOrigin-RevId: 609010175
Change-Id: I90eb921b09068f327b42886ea0a1875374a94049
github-merge-queue bot pushed a commit that referenced this issue Feb 21, 2024
…rder for WORKSPACE repo rules (#21457)

Follow-up to
1cbf09d;
beyond not recording those entries in the marker file, we shouldn't even
record them in memory in the first place. This avoids nasty problems
with unexported repo rules (gah) and should be an extremely tiny
performance win as a bonus...

Fixes #21451

Commit
e84d053

PiperOrigin-RevId: 609010175
Change-Id: I90eb921b09068f327b42886ea0a1875374a94049

Co-authored-by: Googler <wyv@google.com>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

6 participants