Skip to content

Commit 79d8cbd

Browse files
committed
Module cleanup agent: forbid hoisting non-capturing lambdas into static fields
The existing rule only forbade flagging/fixing non-capturing lambdas as allocation issues, which allowed the agent to rationalize hoisting them into private static final fields under other justifications (e.g., "matching the singletons pattern"). The singleton accessor pattern in .github/copilot-instructions.md applies to stored singleton fields like Instrumenter, not arbitrary lambda expressions. Tighten the rule to forbid the hoist regardless of justification, matching the corresponding review-side guidance already in .github/agents/knowledge/general-rules.md.
1 parent ccd1942 commit 79d8cbd

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

.github/agents/module-cleanup.agent.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,13 @@ Auto-fix boundaries:
290290
- Never change:
291291
- literal type suffixes (e.g., `200``200L` or vice-versa) — Java widens
292292
automatically; both forms compile identically and the change is noise
293-
- non-capturing lambdas or method references as allocation issues; do not flag,
294-
fix, or justify changes to these as per-call allocations. On HotSpot /
295-
OpenJDK 8+, these are cached at the call site.
293+
- non-capturing lambdas or method references: never hoist an inline
294+
non-capturing lambda or method reference into a `private static final` field,
295+
regardless of justification (allocation, "pattern consistency", matching a
296+
singletons style, or otherwise). On HotSpot / OpenJDK 8+, these are cached
297+
at the `invokedynamic` call site, so the hoist is pure noise. The singleton
298+
accessor pattern applies to stored singleton fields (e.g. `Instrumenter`),
299+
not to arbitrary lambda expressions.
296300

297301
Output content rules:
298302

0 commit comments

Comments
 (0)