Bazel crashed when querying external repositories with none-rule targets
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
```
FATAL: [0mbazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@WORKSPACE' (requested by nodes 'IGNORED_PACKAGE_PREFIXES:@WORKSPACE')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:642)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382)
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.ClassCastException: class com.google.devtools.build.lib.packages.InputFile cannot be cast to class com.google.devtools.build.lib.packages.Rule (com.google.devtools.build.lib.packages.InputFile and com.google.devtools.build.lib.packages.Rule are in unnamed module of loader 'app')
at com.google.devtools.build.lib.packages.Package.getRule(Package.java:656)
at com.google.devtools.build.lib.repository.ExternalPackageHelper$ExternalPackageRuleExtractor.processAndShouldContinue(ExternalPackageHelper.java:144)
at com.google.devtools.build.lib.repository.ExternalPackageHelper.iterateWorkspaceFragments(ExternalPackageHelper.java:118)
at com.google.devtools.build.lib.repository.ExternalPackageHelper.getRuleByName(ExternalPackageHelper.java:52)
at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.getRepoRuleFromWorkspace(RepositoryDelegatorFunction.java:446)
at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:285)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:571)
... 7 more
```
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
1. Query for all external repositories `bazel query //external:* --output label`
2. Process the list like this:
```
var externals = ... // all labels (lines) returned by first query
var setOfExternalsToQuery = externals.stream()
.filter(s -> s.startsWith("//external:"))
.map(s -> s.substring("//external:".length()))
.map(s -> format("@%s//...", s))
.collect(joining(" "));
var javaImportQuery = String.format("kind('java_import rule', set( %s ))", setOfExternalsToQuery);
```
Something in `setOfExternalsToQuery` is triggering the behavior.
Workaround/fix, ensure the first query is properly scoped, eg. : `kind(jvm_import_external, //external:*)`
**Note**, this requires a workspace with an external repository triggering the behavior. I'm unable to share the workspace I have.
### Which operating system are you running Bazel on?
mac
### What is the output of `bazel info release`?
6.1.0
### 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 master; git rev-parse HEAD` ?
_No response_
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start with the two queries in the reproduction steps, using a workspace with an external repository that triggers the crash. Read com.google.devtools.build.lib.repository.ExternalPackageHelper.java and com.google.devtools.build.lib.packages.Package.java around the stack-trace locations, then trace the call from RepositoryDelegatorFunction.java. Done means the scoped external-repository query no longer crashes when none-rule targets are present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100