You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stop copying comment text through reflection in JavacTokens #286
google-java-format#1546 (merged 2026-11-27, copybara export) removes a per-comment reflection call from the tokenizer wrapper. The code only needs each comment's start and end offsets, but it looked up the private reader field of JavaTokenizer (a lookup that fails on JDK 15 and later), then reflectively called getRawCharacters to build a string just to take its length. Upstream now records the offsets directly, builds the input buffer with getChars into one array, and deletes the unused reflection metadata.
Why it matters to us: our JavacTokens.CommentSavingTokenizer.processComment still contains exactly this pattern (getRawCharactersReflectively, with getDeclaredField("reader") and a fallback after the exception), and it runs for every comment in every formatted file. The change is a small performance and robustness gain, and it drops reflective access into javac internals. Caveat: our CommentWithTextAndPosition keeps an AccessibleReader with the comment text and our code may use that text elsewhere, so the upstream diff does not apply as is; check which of our callers read the text before removing it. No formatting output changes, so no examples.
Suggested action: investigate. If nothing needs the comment text from the tokenizer, adopt the idea (offsets only, single buffer); otherwise limit the change to avoiding the failing getDeclaredField("reader") lookup. Related earlier ticket on performance: 2026-11-20-google-stringwrapper-performance.md.
Filed from an upstream-watch ticket after manual review.
Activity
Stop copying comment text through reflection in JavacTokens
Stop copying comment text through reflection in JavacTokens