Skip to content

Commit 18a6a20

Browse files
jincopybara-github
authored andcommitted
Use RuleConfiguredTarget#getActions everywhere instead of accessing the actions field to piggyback on the null check.
PiperOrigin-RevId: 709344848 Change-Id: Ie9bf68b8a68c6ca0dabe90be03871430bd21e214
1 parent 720e15e commit 18a6a20

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ public final class RuleConfiguredTarget extends AbstractConfiguredTarget {
8282
private final RuleClassId ruleClassId;
8383

8484
/**
85-
* Operations accessing actions, for example, executing them should be performed in the same Bazel
86-
* instance that constructs the {@code RuleConfiguredTarget} instance and not on a Bazel instance
87-
* that retrieves it remotely using deserialization.
85+
* Operations accessing actions (for example, executing them or looking up metadata in them)
86+
* should be performed in the same Bazel instance that constructs the {@code RuleConfiguredTarget}
87+
* instance and not on a Bazel instance that retrieves the {@code RuleConfiguredTarget} remotely
88+
* using deserialization, because actions will be null then.
89+
*
90+
* <p>Prefer using {@link #getActions()} which guards against null actions with a clear error.
8891
*/
8992
@Nullable // Null if deserialized.
9093
private final transient ImmutableList<ActionAnalysisMetadata> actions;
@@ -254,7 +257,7 @@ protected Object rawGetStarlarkProvider(String providerKey) {
254257
// Only expose actions which are legitimate Starlark values, otherwise they will later
255258
// cause a Bazel crash.
256259
// TODO(cparsons): Expose all actions to Starlark.
257-
return actions.stream()
260+
return getActions().stream()
258261
.filter(action -> action instanceof ActionApi)
259262
.collect(ImmutableList.toImmutableList());
260263
}
@@ -299,7 +302,7 @@ public Artifact findArtifactByOutputLabel(Label outputLabel) {
299302
outputLabel,
300303
this);
301304
PathFragment relativeOutputPath = outputLabel.toPathFragment();
302-
for (ActionAnalysisMetadata action : actions) {
305+
for (ActionAnalysisMetadata action : getActions()) {
303306
for (Artifact output : action.getOutputs()) {
304307
if (output.getExecPath().endsWith(relativeOutputPath)) {
305308
return output;

0 commit comments

Comments
 (0)