Skip to content

Avoid copying comment text via reflection in JavacTokens - #1546

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1029340664
Nov 27, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1029340664

Conversation

@copybara-service

Copy link
Copy Markdown

Avoid copying comment text via reflection in JavacTokens

JavacTokens only needs each comment's pos and endPos, not its text. Previously CommentSavingTokenizer called JavaTokenizer.class.getDeclaredField("reader") on every comment (throwing NoSuchFieldException since JDK 15, where JavaTokenizer extends UnicodeReader), then reflectively invoked getRawCharacters(int, int) to allocate a String solely for its length.

Store RawTok(null, pos, endPos) directly, copy source and EOF_COMMENT into a single char[] buffer, and remove the unused reflection metadata entries.

`JavacTokens` only needs each comment's `pos` and `endPos`, not its text. Previously `CommentSavingTokenizer` called `JavaTokenizer.class.getDeclaredField("reader")` on every comment (throwing `NoSuchFieldException` since JDK 15, where `JavaTokenizer` extends `UnicodeReader`), then reflectively invoked `getRawCharacters(int, int)` to allocate a `String` solely for its length.

Store `RawTok(null, pos, endPos)` directly, copy `source` and `EOF_COMMENT` into a single `char[]` buffer, and remove the unused reflection metadata entries.

PiperOrigin-RevId: 1031169705
@copybara-service
copybara-service Bot merged commit 1f20730 into master Nov 27, 2026
4 checks passed
@copybara-service
copybara-service Bot deleted the test_1029340664 branch November 27, 2026 11:52
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.

1 participant