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

Bazel NPE when setting --java_classpath=bazel #16635

Closed
arunkumar9t2 opened this issue Nov 2, 2022 · 3 comments
Closed

Bazel NPE when setting --java_classpath=bazel #16635

arunkumar9t2 opened this issue Nov 2, 2022 · 3 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug

Comments

@arunkumar9t2
Copy link
Contributor

arunkumar9t2 commented Nov 2, 2022

Description of the bug:

Setting --java_classpath=bazel on the command line and building a simple project crashes bazel with following stacktrace

java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=ConfiguredTargetKey{label=//classpath:B_Java, config=BuildConfigurationKey[62ff62eac06d5b2a3021fd76848185e8623f28c27a49346ecc5997f2c301b7b9]}, actionIndex=0}' (requested by nodes 'TargetCompletionKey{topLevelArtifactContext=com.google.devtools.build.lib.analysis.TopLevelArtifactContext@90904c3b, actionLookupKey=ConfiguredTargetKey{label=//classpath:A_Java, config=BuildConfigurationKey[62ff62eac06d5b2a3021fd76848185e8623f28c27a49346ecc5997f2c301b7b9]}, willTest=false}')
	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.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at com.google.devtools.build.lib.rules.java.JavaCompileAction.getReducedClasspath(JavaCompileAction.java:262)
	at com.google.devtools.build.lib.rules.java.JavaCompileAction.beginExecution(JavaCompileAction.java:404)
	at com.google.devtools.build.lib.actions.Action.execute(Action.java:133)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$5.execute(SkyframeActionExecutor.java:936)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.continueAction(SkyframeActionExecutor.java:1103)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.run(SkyframeActionExecutor.java:1061)
	at com.google.devtools.build.lib.skyframe.ActionExecutionState.runStateMachine(ActionExecutionState.java:160)
	at com.google.devtools.build.lib.skyframe.ActionExecutionState.getResultOrDependOnFuture(ActionExecutionState.java:93)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeAction(SkyframeActionExecutor.java:503)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:826)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.computeInternal(ActionExecutionFunction.java:323)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:161)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:571)

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

Add a simple java_library and build it with --java_classpath=bazel

Which operating system are you running Bazel on?

MacOS Monterey 12.4

What is the output of bazel info release?

development version

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

Branched off master and built with bazelisk build //src:bazel.

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

https://github.com/bazelbuild/bazel.git
19b8d24531fb728701a85ec050361d434600b5d2
19b8d24531fb728701a85ec050361d434600b5d2

Have you found anything relevant by searching the web?

The error is caused to JavaCompileActionContext not being registered to ActionContextRegistry

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

N/A

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Nov 17, 2022
@cushon
Copy link
Contributor

cushon commented Dec 5, 2022

There was some additional context/motivation in #16906

See #16426 (comment)

Originally the reduced classpath reduction happened during action execution, so changes in inputs would cause invalidation even if those inputs were pruned off the reduced classpath. But the classpath reduction now happens in Bazel, so in the example if libZ changes the action will still be a cache hit and won't be reexecuted:
https://cs.github.com/bazelbuild/bazel/blob/60ded2b53d4d9180c213e9e44a8c640368e60822/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java#L244

That optimization was implemented for Blaze, but parts of it are not wired up in Bazel, and attempting to enable it results in an NPE.

This bug tracks making --experimental_java_classpath=bazel work, to improve performance of incremental Java builds.

benjaminp added a commit to benjaminp/bazel that referenced this issue Dec 5, 2022
This makes --experimental_java_classpath=bazel work.

This CL is similar to bazelbuild#16636 but applies the code review feedback. (Though, I put the context registration in BazelRulesModule rather than BazelStrategyModule as JavaCompileActionContext isn't really an strategy.)

Fixes bazelbuild#16635.
benjaminp added a commit to benjaminp/bazel that referenced this issue Dec 6, 2022
This makes --experimental_java_classpath=bazel work.

This CL is similar to bazelbuild#16636 but applies the code review feedback. (Though, I put the context registration in BazelRulesModule rather than BazelStrategyModule as JavaCompileActionContext isn't really a strategy.)

Fixes bazelbuild#16635.
benjaminp added a commit to benjaminp/bazel that referenced this issue Dec 6, 2022
This makes --experimental_java_classpath=bazel work.

This CL is similar to bazelbuild#16636 but applies the code review feedback. (Though, I put the context registration in BazelRulesModule rather than BazelStrategyModule as JavaCompileActionContext isn't really a strategy.)

Fixes bazelbuild#16635.
@arunkumar9t2
Copy link
Contributor Author

Thanks @cushon yes that was the motivation for us as well since we wanted to do classpath reduction before execution to leverage compile avoidance.

ShreeM01 added a commit that referenced this issue Jan 25, 2023
This makes --experimental_java_classpath=bazel work.

This CL is similar to #16636 but applies the code review feedback. (Though, I put the context registration in BazelRulesModule rather than BazelStrategyModule as JavaCompileActionContext isn't really a strategy.)

Fixes #16635.

Closes #16921.

PiperOrigin-RevId: 494950719
Change-Id: Ia32e2d0e67ddacaf18ba52591f7b67b3c6c7b792

Co-authored-by: Benjamin Peterson <benjamin@engflow.com>
@raviagarwal7
Copy link

@arunkumar9t2 could you share some docs on how does --java_classpath=bazel help in classpath reduction?
how is it different from --experimental_strict_java_deps or --experimental_prune_transitive_deps (being added in #16426)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug
Projects
None yet
5 participants