AVRO-4313: [java] Clarify javaAnnotation validation comments - #3907
Merged
Conversation
Rewrite the comments around the annotation-validation grammar and its regression test in plainer language. Explain why the check exists (the javaAnnotation property is emitted verbatim into generated source) and what an unescaped quote in a string literal would allow, so the intent is clear to readers who are not familiar with the regex. Comment-only change; no behavior change.
iemejia
force-pushed
the
AVRO-4313-clarify-comments
branch
from
July 31, 2026 19:50
0cb972b to
2e5bf47
Compare
There was a problem hiding this comment.
Pull request overview
This PR clarifies the security rationale and mechanics behind javaAnnotation validation in the Java SpecificCompiler, and improves the readability of the associated regression test commentary (AVRO-4313 follow-up). The changes are comment-only and do not alter behavior.
Changes:
- Rewrites the
annotationCannotBreakOutViaStringLiteraltest comments to more plainly explain the injection scenario and why the assertion checks for unescaped quotes in generated code. - Adds a clearer, higher-level comment block in
SpecificCompilerdescribing whyjavaAnnotationis validated and what the regex sub-patterns are intended to prevent.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java | Clarifies the regression test’s intent and how it distinguishes safe schema-string embedding from unsafe verbatim code emission. |
| lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java | Adds clearer documentation for the javaAnnotation validation grammar and the string-literal constraints that prevent code injection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
RyanSkraba
approved these changes
Aug 2, 2026
Contributor
|
Thanks -- it's important for these complicated PRs! |
Contributor
|
Cherry-picked to branch-1.12. |
RyanSkraba
pushed a commit
that referenced
this pull request
Aug 2, 2026
Rewrite the comments around the annotation-validation grammar and its regression test in plainer language. Explain why the check exists (the javaAnnotation property is emitted verbatim into generated source) and what an unescaped quote in a string literal would allow, so the intent is clear to readers who are not familiar with the regex. Comment-only change; no behavior change.
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.
What is the purpose of the change
Follow-up to AVRO-4313 / #3892. That fix tightened the regex that validates a
schema's
javaAnnotationbefore it is copied verbatim into generated Javasource. The surrounding comments (and the regression test comments) were hard
to follow, so this rewrites them in plainer language.
The comments now explain:
javaAnnotationproperty is emitted verbatiminto generated source, so it must be validated first;
running past its closing quote and swallowing injected code;
payload inside the
SCHEMA$constant from a real verbatim emission.This is a comment-only change; no behavior change.
Verifying this change
This change is a trivial rework / code cleanup without any test coverage.
The existing
annotationCannotBreakOutViaStringLiteraland the rest of thecompilermodule suite continue to pass.Documentation