Skip to content

fix: skip plugins without processor_classes in annotation processor classification - #1545

Open
jianingxu1 wants to merge 1 commit into
bazel-contrib:masterfrom
jianingxu1:fix/annotation-processor-filter-errorprone
Open

fix: skip plugins without processor_classes in annotation processor classification#1545
jianingxu1 wants to merge 1 commit into
bazel-contrib:masterfrom
jianingxu1:fix/annotation-processor-filter-errorprone

Conversation

@jianingxu1

@jianingxu1 jianingxu1 commented Apr 1, 2026

Copy link
Copy Markdown

Problem

Non-annotation-processor plugins are being misclassified as annotation processors.

Context:
We are using kt_jvm_library with mixed Java/Kotlin sources, and we want to use Error Prone as a java_plugin via the plugins attribute, so that Error Prone runs as a javac plugin on the Java sources.

Problem:
When no annotation processors are passed in, and Error Prone is passed, running bazel build <target> fails on javac step, throwing
error: package <package> does not exist and error: cannot find symbol errors on Kotlin pkgs/symbols.

An Error Prone java_plugin has processor_jars but no processor_classes. However, _targets_to_annotation_processors includes it because it only checks for processor_jars, misclassifying it as an annotation processor.

This causes:

  1. KAPT is triggered but the src_main-kapt-generated-stub.jar in kt_stubs_for_java is empty (since there were no real processors to generate stubs). Code reference.
  2. The Kotlin compile jar is not added to kt_stubs_for_java (compile.bzl:968). It is only populated when annotation_processors is empty (given Kotlin sources are present).
  3. When building Java, Java sources that reference Kotlin symbols fail with missing symbols errors.

In Bazel, java_plugin covers both annotation processors (declare processor_class) and javac plugins like Error Prone (no processor_class). Only the former should go through KAPT.

Note that: if both ErrorProne and an annotator processor are provided, this issue does not happen.

Fix

In _targets_to_annotation_processors (kotlin/internal/jvm/plugins.bzl), also require processor_classes to be non-empty:

- if p.processor_jars:
+ if p.processor_jars and p.processor_classes.to_list():

Error Prone is still picked up correctly as a javac plugin via the plugins attribute in _run_kt_builder_action, it just no longer incorrectly triggers KAPT and not passing kt_stubs_for_java.

Testing

  • bazel test //src/...

…cessor_classes

Prevents ErrorProne (and other javac plugins) from being misclassified as
annotation processors. A java_plugin without processor_class is a javac plugin
(e.g. Error Prone), not an APT processor — only add it to the annotation
processor list if processor_classes is non-empty.

Ported from uber-code/java-code#13954 (rules_kotlin_annotation_processor_filter.patch).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jianingxu1
jianingxu1 marked this pull request as draft April 1, 2026 12:58
@jianingxu1
jianingxu1 marked this pull request as ready for review April 1, 2026 14:13
@jianingxu1
jianingxu1 marked this pull request as draft April 1, 2026 14:35
@jianingxu1
jianingxu1 marked this pull request as ready for review April 1, 2026 15:03
@restingbull

Copy link
Copy Markdown
Collaborator

Please add a repro case for this -- we'd rather not have it break later silently later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants