fix: skip plugins without processor_classes in annotation processor classification - #1545
Open
jianingxu1 wants to merge 1 commit into
Open
Conversation
…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
requested review from
Bencodes,
agluszak,
ahumesky and
restingbull
as code owners
April 1, 2026 12:55
jianingxu1
marked this pull request as draft
April 1, 2026 12:58
jianingxu1
marked this pull request as ready for review
April 1, 2026 14:13
jianingxu1
marked this pull request as draft
April 1, 2026 14:35
jianingxu1
marked this pull request as ready for review
April 1, 2026 15:03
Collaborator
|
Please add a repro case for this -- we'd rather not have it break later silently later on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Non-annotation-processor plugins are being misclassified as annotation processors.
Context:
We are using
kt_jvm_librarywith mixed Java/Kotlin sources, and we want to use Error Prone as ajava_pluginvia thepluginsattribute, so that Error Prone runs as ajavacplugin on the Java sources.Problem:
When no annotation processors are passed in, and Error Prone is passed, running
bazel build <target>fails onjavacstep, throwingerror: package <package> does not existanderror: cannot find symbolerrors on Kotlin pkgs/symbols.An Error Prone
java_pluginhasprocessor_jarsbut noprocessor_classes. However,_targets_to_annotation_processorsincludes it because it only checks forprocessor_jars, misclassifying it as an annotation processor.This causes:
src_main-kapt-generated-stub.jarinkt_stubs_for_javais empty (since there were no real processors to generate stubs). Code reference.kt_stubs_for_java(compile.bzl:968). It is only populated whenannotation_processorsis empty (given Kotlin sources are present).In Bazel,
java_plugincovers both annotation processors (declareprocessor_class) and javac plugins like Error Prone (noprocessor_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 requireprocessor_classesto be non-empty:Error Prone is still picked up correctly as a javac plugin via the
pluginsattribute in_run_kt_builder_action, it just no longer incorrectly triggers KAPT and not passingkt_stubs_for_java.Testing
bazel test //src/...