[improve][ci] Document avoiding reflection in tests in Copilot review instructions#25636
Merged
merlimat merged 1 commit intoapache:masterfrom Apr 30, 2026
Merged
Conversation
… instructions Add guidance to Copilot review instructions that prohibits using reflection (e.g. WhiteboxImpl, setAccessible) to access private fields or methods from tests, and recommends exposing package-private accessors annotated with @VisibleForTesting instead. Based on the dev@ thread: https://lists.apache.org/thread/7gr04sqmzyttx4ln6ydtp3qv0xgo1o6m
merlimat
approved these changes
Apr 30, 2026
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.
Motivation
The Pulsar codebase has accumulated many tests that use reflection (
WhiteboxImpl.getInternalState,setAccessible(true), etc.) to read or mutate private fields of the class under test. This pattern was discussed on the dev@ mailing list:[DISCUSS] Stop using reflection to access private fields in tests
Reflection-based test access:
The discussion concluded that the preferred approach is to expose what tests legitimately need through package-private methods annotated with
@VisibleForTesting, with the test placed in the same package as the class under test.This PR teaches the Copilot PR-review bot to flag reflection-based test access in new code, so the project guidance is enforced consistently in reviews going forward.
Modifications
.github/copilot-instructions.md:@VisibleForTestingpackage-private pattern, before/after examples (WhiteboxImpl.getInternalStatevs. a typed getter), and a link to the dev@ thread.Verifying this change
This change is a trivial rework / code cleanup without any test coverage. It only modifies Copilot reviewer guidance in
.github/copilot-instructions.md; there is no production or test code change.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes