Skip to content

Avoid opening unannotated methods during parameter discovery - #618

Merged
mkarg merged 1 commit into
cbeust:masterfrom
JimmyLiuJia:fix/annotated-method-access
Nov 2, 2026
Merged

mkarg merged 1 commit into
cbeust:masterfrom
JimmyLiuJia:fix/annotated-method-access

Conversation

@JimmyLiuJia

Copy link
Copy Markdown
Contributor

Discovering options on a @ParametersDelegate implementing BiPredicate attempts to open unannotated private methods in java.util.function and fails with InaccessibleObjectException.

Only change method accessibility after finding @Parameter, @DynamicParameter or @ParametersDelegate. Add a regression that parses a private delegate field and a private annotated setter on a BiPredicate implementation; it fails with the reported exception before the fix.

Validation: clean check assemble passed with 339 tests, zero failures, errors or skips on Windows with Temurin 25.0.4.1 and Gradle 9.8.0. Local validation used installed Gradle 9.8.0; the repository wrapper specifies 9.7.1.

Fixes #582

AI assistance: OpenAI Codex wrote the fix and regression test, ran validation, and drafted this PR.

@mkarg mkarg added the bug Bug label Nov 2, 2026
@mkarg mkarg self-assigned this Nov 2, 2026
@mkarg
mkarg requested a balanced review from Copilot November 2, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change that avoids opening unannotated delegate methods.

No open issues 🎉

What changed in this PR

Fixes #582 by preventing parameter discovery from opening unannotated methods, avoiding InaccessibleObjectException for delegates implementing BiPredicate.

Changes:

  • Only change method accessibility after finding a supported parameter annotation.
  • Add a regression test covering a private delegate field, private annotated field, and private annotated setter on a BiPredicate implementation.
File Description
src/​test/​java/​com/​beust/​jcommander/​ParametersDelegateTest.java Adds regression coverage for parsing a delegate implementing BiPredicate.
src/​main/​java/​com/​beust/​jcommander/​Parameterized.java Skips unannotated methods before changing accessibility.

Review effort: Balanced

@mkarg
mkarg merged commit 1b4fb69 into cbeust:master Nov 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ParametersDelegate fails if delegate class implements BiPredicate

3 participants