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

Fix NPE when setting --java_classpath=bazel #16636

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/query2:aquery-utils",
"//src/main/java/com/google/devtools/build/lib/query2/engine",
"//src/main/java/com/google/devtools/build/lib/query2/query/output",
"//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation-context",
"//src/main/java/com/google/devtools/build/lib/runtime/events",
"//src/main/java/com/google/devtools/build/lib/server",
"//src/main/java/com/google/devtools/build/lib/server:pid_file_watcher",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.profiler.SilentCloseable;
import com.google.devtools.build.lib.rules.java.JavaCompileActionContext;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
Expand All @@ -102,6 +103,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
Expand All @@ -116,6 +118,7 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -184,6 +187,10 @@ public class ExecutionTool {
.restrictTo(WorkspaceStatusAction.Context.class, "")
.restrictTo(SymlinkTreeActionContext.class, "");

// Register JavaCompileActionContext for java_classpath=bazel to work
actionContextRegistryBuilder.register(
JavaCompileActionContext.class, new JavaCompileActionContext());

Comment on lines +190 to +193
Copy link
Contributor

Choose a reason for hiding this comment

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

A better location to do this registration is BazelStrategyModule overriding registeringActionContext. The module allows for better extensibility, that is potential use of a different compilation context.

Please move it there.

this.prefetcher = executorBuilder.getActionInputPrefetcher();
this.executorLifecycleListeners = executorBuilder.getExecutorLifecycleListeners();

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/google/devtools/build/lib/rules/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ java_library(
],
)

java_library(
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bad practice to have a source file part of two rules. Please remove JavaCompileActgionContext.java from the other rule where it's still used and fix dependencies if needed.

name = "java-compilation-context",
srcs = [
"JavaCompileActionContext.java",
],
visibility = ["//visibility:public"],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/protobuf:deps_java_proto",
],
)

java_library(
name = "java-compilation",
srcs = [
Expand Down