Copilot commented on code in PR #2438:
URL: https://github.com/apache/groovy/pull/2438#discussion_r3069450630


##########
src/main/java/org/codehaus/groovy/ast/ClassNode.java:
##########
@@ -1452,17 +1452,21 @@ public ClassNode getOuterClass() {
         return null;
     }
 
+    private List<ClassNode> outerClasses;
     public List<ClassNode> getOuterClasses() {
+        List<ClassNode> ocs = outerClasses;
+        if (ocs != null) return ocs;
+
         ClassNode outer = getOuterClass();
         if (outer == null) {
-            return Collections.emptyList();
+            return outerClasses = Collections.emptyList();
         }
         List<ClassNode> result = new ArrayList<>(4);
         do {
             result.add(outer);
         } while ((outer = outer.getOuterClass()) != null);
 
-        return result;
+        return outerClasses = Collections.unmodifiableList(result);

Review Comment:
   `getOuterClasses()` now caches the computed list in a field, but the 
implementation doesn’t account for redirect/proxy `ClassNode`s. Since 
`setRedirect(...)` can be called later for non-primary nodes, a proxy may cache 
`Collections.emptyList()` (or an outdated chain) before redirect is set/changed 
and then return stale results thereafter. Consider delegating to 
`redirect().getOuterClasses()` when `redirect != null` and/or clearing 
`outerClasses` in `setRedirect(...)` to keep the cache correct.



-- 
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