Skip to content

Conversation

@bazel-io
Copy link
Member

All the values have to be checked for nullness individually.

Fixes the following two NPEs:

  1. refactor: Remove next batch of WORKSPACE content bazel-contrib/rules_go#4531 (comment)
java.lang.NullPointerException: Cannot invoke "com.google.devtools.build.lib.skyframe.PackageValue.getPackage()" because the return value of "com.google.devtools.build.skyframe.SkyframeLookupResult.getOrThrow(com.google.devtools.build.skyframe.SkyKey, java.lang.Class)" is null
	at com.google.devtools.build.lib.skyframe.TestExpansionFunction.getPrerequisites(TestExpansionFunction.java:169)
	at com.google.devtools.build.lib.skyframe.TestExpansionFunction.computeExpandedTests(TestExpansionFunction.java:85)
...
  1. Crash while DirectoryTreeDigestFunction.getSubDirTreeDigests #27942
java.lang.NullPointerException
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
	at com.google.devtools.build.lib.skyframe.DirectoryTreeDigestFunction.getSubDirTreeDigests(DirectoryTreeDigestFunction.java:140)
	at com.google.devtools.build.lib.skyframe.DirectoryTreeDigestFunction.compute(DirectoryTreeDigestFunction.java:65)

Speculative fix for #27942

Closes #27959.

PiperOrigin-RevId: 843808256
Change-Id: I012756ec8a641c68bca31fe155d230caa00d8a3f

Commit 1025821

All the values have to be checked for nullness individually.

Fixes the following two NPEs:
1. bazel-contrib/rules_go#4531 (comment)
```
java.lang.NullPointerException: Cannot invoke "com.google.devtools.build.lib.skyframe.PackageValue.getPackage()" because the return value of "com.google.devtools.build.skyframe.SkyframeLookupResult.getOrThrow(com.google.devtools.build.skyframe.SkyKey, java.lang.Class)" is null
	at com.google.devtools.build.lib.skyframe.TestExpansionFunction.getPrerequisites(TestExpansionFunction.java:169)
	at com.google.devtools.build.lib.skyframe.TestExpansionFunction.computeExpandedTests(TestExpansionFunction.java:85)
...
```
2. bazelbuild#27942
```
java.lang.NullPointerException
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
	at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
	at com.google.devtools.build.lib.skyframe.DirectoryTreeDigestFunction.getSubDirTreeDigests(DirectoryTreeDigestFunction.java:140)
	at com.google.devtools.build.lib.skyframe.DirectoryTreeDigestFunction.compute(DirectoryTreeDigestFunction.java:65)
```

Speculative fix for bazelbuild#27942

Closes bazelbuild#27959.

PiperOrigin-RevId: 843808256
Change-Id: I012756ec8a641c68bca31fe155d230caa00d8a3f
@bazel-io bazel-io added the awaiting-review PR is awaiting review from an assigned reviewer label Dec 12, 2025
@bazel-io bazel-io requested a review from a team as a code owner December 12, 2025 21:19
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes two NullPointerExceptions that occurred from incorrect usage of SkyframeLookupResult. The changes ensure that values retrieved from the result are checked for nullness before being used. My review includes one suggestion to improve performance in DirectoryTreeDigestFunction.java by avoiding a double iteration over the collection of keys.

Comment on lines +133 to +141
if (env.valuesMissing()
|| dirTreeDigestValueKeys.stream().map(result::get).anyMatch(Objects::isNull)) {
return null;
}
return dirTreeDigests;
return dirTreeDigestValueKeys.stream()
.map(result::get)
.map(DirectoryTreeDigestValue.class::cast)
.map(DirectoryTreeDigestValue::hexDigest)
.collect(toImmutableList());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly fixes the NullPointerException, it iterates over dirTreeDigestValueKeys twice: once to check for nulls and a second time to collect the digests. This could be inefficient for a large number of keys. You can accomplish this more efficiently in a single pass using a traditional for-loop with a builder.

    ImmutableList.Builder<String> digests =
        ImmutableList.builderWithExpectedSize(dirTreeDigestValueKeys.size());
    for (SkyKey key : dirTreeDigestValueKeys) {
      var value = (DirectoryTreeDigestValue) result.get(key);
      if (value == null) {
        // A value is missing. Skyframe will restart.
        return null;
      }
      digests.add(value.hexDigest());
    }
    return digests.build();

@iancha1992 iancha1992 enabled auto-merge December 12, 2025 23:57
@iancha1992 iancha1992 added team-Rules-CPP Issues for C++ rules team-Local-Exec Issues and PRs for the Execution (Local) team labels Dec 12, 2025
@iancha1992 iancha1992 added this pull request to the merge queue Dec 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 15, 2025
@meteorcloudy meteorcloudy added this pull request to the merge queue Dec 15, 2025
Merged via the queue into bazelbuild:release-8.6.0 with commit 3c27607 Dec 15, 2025
47 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Local-Exec Issues and PRs for the Execution (Local) team team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants