Skip to content

Fix field accessibility leak in EnhancedCompositeBeanHelper#11425

Merged
gnodet merged 2 commits intoapache:masterfrom
gnodet:fix/field-accessibility-leak
Nov 12, 2025
Merged

Fix field accessibility leak in EnhancedCompositeBeanHelper#11425
gnodet merged 2 commits intoapache:masterfrom
gnodet:fix/field-accessibility-leak

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Nov 10, 2025

The previous implementation cached field accessibility state globally, which could cause issues when the same field is accessed from different contexts or security managers. This was particularly problematic in plugin unit tests where fields would remain accessible after being set.

The fix ensures that field accessibility is properly restored to its original state after setting field values, preventing accessibility state from leaking between different bean instances.

Added unit tests to verify:

  • Field accessibility is restored after setting values
  • Multiple field accesses don't leak accessibility state
  • The fix works correctly across different bean instances

This resolves the issue reported on the dev list regarding compiler plugin unit test failures related to field accessibility.

The previous implementation cached field accessibility state globally,
which could cause issues when the same field is accessed from different
contexts or security managers. This was particularly problematic in
plugin unit tests where fields would remain accessible after being set.

The fix ensures that field accessibility is properly restored to its
original state after setting field values, preventing accessibility
state from leaking between different bean instances.

Added unit tests to verify:
- Field accessibility is restored after setting values
- Multiple field accesses don't leak accessibility state
- The fix works correctly across different bean instances

This resolves the issue reported on the dev list regarding compiler
plugin unit test failures related to field accessibility.
@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Nov 10, 2025
Copy link
Contributor

@desruisseaux desruisseaux left a comment

Choose a reason for hiding this comment

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

I verified that together with #11429 and apache/maven-compiler-plugin#991 it allows the JUnit tests and integration tests of the compiler plugin to pass.

} else if (!isAccessible) {
boolean wasAccessible = field.canAccess(bean);
if (!wasAccessible) {
field.setAccessible(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This code assumes that the same Field object will not be set by two threads in same time. It seems to imply that EnhancedCompositeBeanHelper is not really thread-safe. If this limitation okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I'll remove the setAccessible(false), as once the field has been made accessible, there's no real need to un-expose it.

@gnodet gnodet merged commit 6e30ae6 into apache:master Nov 12, 2025
41 of 42 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Nov 12, 2025
gnodet added a commit to gnodet/maven that referenced this pull request Nov 12, 2025
…1425)

The previous implementation cached field accessibility state globally,
which could cause issues when the same field is accessed from different
contexts or security managers. This was particularly problematic in
plugin unit tests where fields would remain accessible after being set.

The fix ensures that field accessibility is properly restored to its
original state after setting field values, preventing accessibility
state from leaking between different bean instances.

Added unit tests to verify:
- Field accessibility is restored after setting values
- Multiple field accesses don't leak accessibility state
- The fix works correctly across different bean instances

This resolves the issue reported on the dev list regarding compiler
plugin unit test failures related to field accessibility.

(cherry picked from commit 6e30ae6)
@gnodet
Copy link
Contributor Author

gnodet commented Nov 12, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit that referenced this pull request Nov 13, 2025
…11433)

The previous implementation cached field accessibility state globally,
which could cause issues when the same field is accessed from different
contexts or security managers. This was particularly problematic in
plugin unit tests where fields would remain accessible after being set.

The fix ensures that field accessibility is properly restored to its
original state after setting field values, preventing accessibility
state from leaking between different bean instances.

Added unit tests to verify:
- Field accessibility is restored after setting values
- Multiple field accesses don't leak accessibility state
- The fix works correctly across different bean instances

This resolves the issue reported on the dev list regarding compiler
plugin unit test failures related to field accessibility.

(cherry picked from commit 6e30ae6)
@gnodet gnodet deleted the fix/field-accessibility-leak branch November 14, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants