gnodet-bot commented on code in PR #14028:
URL: https://github.com/apache/maven/pull/14028#discussion_r4592652014


##########
impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java:
##########
@@ -298,11 +301,19 @@ private Object convertProperty(
     }
 
     /**
-     * Set field value with cached accessibility.
+     * Set field value with cached accessibility to avoid repeated 
canAccess()/setAccessible() calls.
      */
     private void setFieldValue(Object bean, Field field, Object value) throws 
IllegalAccessException {
-        if (!field.canAccess(bean)) {
+        Boolean isAccessible = ACCESSIBLE_FIELD_CACHE.get(field);
+        if (isAccessible == null) {
+            isAccessible = field.canAccess(bean);
+            if (!isAccessible) {
+                field.setAccessible(true);
+            }
+            ACCESSIBLE_FIELD_CACHE.put(field, isAccessible);
+        } else if (!isAccessible) {
             field.setAccessible(true);
+            ACCESSIBLE_FIELD_CACHE.put(field, true);

Review Comment:
   ⚠️ **Cache gives no benefit for the inaccessible case.**
   
   When `canAccess(bean)` returned `false` on the first call, the cache stores 
`false`. Every subsequent call for this field enters this `else if` branch and 
calls `setAccessible(true)` again — the expensive call is not avoided. The 
cache only saves `canAccess()` for already-accessible fields (the cheap path).
   
   Also: the cache key is `Field` alone, but `canAccess(bean)` depends on the 
specific `bean` instance's runtime class — different bean types can have 
different accessibility for the same `Field`.



##########
impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java:
##########
@@ -52,6 +52,9 @@ public final class EnhancedCompositeBeanHelper {
     // Cache for field lookups: Class -> FieldName -> Field
     private static final ConcurrentMap<Class<?>, Map<String, Field>> 
FIELD_CACHE = new ConcurrentHashMap<>();
 
+    // Cache for field accessibility to avoid repeated 
canAccess()/setAccessible() calls
+    private static final ConcurrentMap<Field, Boolean> ACCESSIBLE_FIELD_CACHE 
= new ConcurrentHashMap<>();

Review Comment:
   🚨 **Accessibility leak re-introduced.**
   
   This cache was deliberately removed in commit 2bfdc6c (fix #11425) because 
`setAccessible(true)` permanently changes the `Field`'s accessibility — no 
restore on exit. Any subsequent caller in any thread sees the field as 
permanently accessible. The same root cause as the original regression is back.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to