This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new 1e581f2d73 Fix field accessibility leak in EnhancedCompositeBeanHelper 
(#14028)
1e581f2d73 is described below

commit 1e581f2d73c2bea9de5ceb5b0c32c93a3a1e9b05
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Nov 17 06:15:29 2026 +0100

    Fix field accessibility leak in EnhancedCompositeBeanHelper (#14028)
    
    Fix: capture the accessibility state before the call, restore it 
unconditionally in a finally block.
---
 .../configuration/internal/EnhancedCompositeBeanHelper.java | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 
a/impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java
 
b/impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java
index 0fbc818b81..38b8d8a5c9 100644
--- 
a/impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java
+++ 
b/impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java
@@ -298,13 +298,20 @@ private Object convertProperty(
     }
 
     /**
-     * Set field value with cached accessibility.
+     * Set field value, restoring accessibility to its original state 
afterward.
      */
     private void setFieldValue(Object bean, Field field, Object value) throws 
IllegalAccessException {
-        if (!field.canAccess(bean)) {
+        boolean wasAccessible = field.canAccess(bean);
+        if (!wasAccessible) {
             field.setAccessible(true);
         }
-        field.set(bean, value);
+        try {
+            field.set(bean, value);
+        } finally {
+            if (!wasAccessible) {
+                field.setAccessible(false);
+            }
+        }
     }
 
     /**

Reply via email to