Skip to content

Commit 2b5ac9e

Browse files
committed
Code review agent: more classLoaderMatcher guidance
1 parent 098ed7a commit 2b5ac9e

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

.github/agents/code-review-and-fix.agent.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,21 @@ Auto-fix boundaries:
154154
same parent and apply the step-by-step procedure in `gradle-conventions.md`.
155155
After adding, verify by running the module's tests.
156156
- missing version comments on `hasClassesNamed()` landmark classes in existing
157-
`classLoaderMatcher()` overrides, including single-class lower-bound checks —
157+
`classLoaderMatcher()` overrides, including single-class checks —
158158
determine each class's **role** (floor vs ceiling) and add the matching comment.
159159
First check: does a **newer** sibling instrumentation module exist for this library
160160
(e.g., `mongo-4.0` next to `mongo-3.7`)? If so, look at what the newer module checks
161161
in *its* `classLoaderMatcher()`. Classes that are present in the newer module's check
162162
but absent from the current module's check (or vice versa) reveal a version boundary —
163163
the class was likely added or removed between versions.
164164
Then determine the comment form for each class:
165-
- **Floor class** (proves "at least version X"): look up when the class was **introduced**
166-
→ comment `// added in X.Y`.
167-
- **Ceiling class** (proves "not yet version Y"): look up when the class was **removed**
168-
→ comment `// removed in Y.Z` (meaning: its presence here ensures we don't match
169-
version Y.Z+ where a different module takes over).
165+
**Floor class** (proves "at least version X"): look up when the class was
166+
**introduced** → comment `// added in X.Y`.
167+
**Ceiling class** (proves "not yet version Y"): look up when the class was
168+
**removed** → comment `// removed in Y.Z` (meaning: its presence here ensures we
169+
don't match version Y.Z+ where a different module takes over).
170+
**Single class that provides both bounds**: include both facts in one comment,
171+
e.g. `// added in X.Y, removed in Y.Z`.
170172
A ceiling class might have been *introduced* much earlier than the module's target version.
171173
Do not use `// added in` for a ceiling class — that is misleading. The relevant fact is
172174
when it was **removed**.

.github/agents/code-review.agent.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ For each file in scope:
9494
5. Do not flag a non-capturing lambda or method reference as an unnecessary allocation,
9595
because on modern JDKs these are typically cached at the call site rather than
9696
allocated on every invocation.
97-
6. Flag a missing `// added in X.Y` comment on a single-class lower-bound
98-
`hasClassesNamed(...)` check in `classLoaderMatcher()` only after validating that the
99-
stated version is factually correct from repository or upstream evidence; the comment
100-
documents why the matcher exists and which version boundary it enforces.
97+
6. Flag a missing version-boundary comment on a single-class `hasClassesNamed(...)`
98+
check in `classLoaderMatcher()` only after validating the stated boundary from
99+
repository or upstream evidence. Use `// added in X.Y` when the class only provides
100+
the lower bound; if the same class also provides the upper bound because it disappears
101+
in a newer sibling version, preserve or request `removed in Y.Z` too.
101102
7. Prevent duplicates:
102103
- If equivalent `REVIEW:` already exists above the same line, do not add another.
103104

.github/agents/knowledge/javaagent-module-patterns.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Place a comment **above each class name string** stating its version role:
8787
- **Floor class** (proves "at least version X"): use `// added in X.Y`.
8888
- **Ceiling class** (proves "not yet version Y"): use `// removed in Y.Z`.
8989

90+
A single landmark class can sometimes provide **both** bounds: its presence proves the
91+
module is at least version `X.Y`, and the same class disappears in `Y.Z`, so its presence
92+
also excludes `Y.Z+`. In that case, a combined comment such as
93+
`// added in X.Y, removed in Y.Z` is appropriate.
94+
9095
**How to identify ceiling classes**: check whether a **newer sibling module** exists for
9196
the same library (e.g., `mongo-4.0` next to `mongo-3.7`). If the newer module's
9297
`classLoaderMatcher()` checks a different variant of the same class (e.g.,
@@ -183,17 +188,20 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
183188
- Floor class → `// added in X.Y` (class introduced in version X.Y).
184189
- Ceiling class → `// removed in Y.Z` (class removed in version Y.Z, ensuring the
185190
module does not activate on Y.Z+).
191+
- Single class that serves as both floor and ceiling → include both boundaries, e.g.
192+
`// added in X.Y, removed in Y.Z`.
186193
Do not use `// added in` for a ceiling class — that states when the class first appeared,
187194
which is irrelevant and misleading; the purpose is the upper bound.
188195
To identify ceiling classes, check if a newer sibling module's `classLoaderMatcher()`
189196
checks a different variant or replacement class.
190-
- **Single-class lower-bound comments are required.** When a single-class
191-
`hasClassesNamed(...)` check exists solely to establish the module's lower bound, add an
192-
inline `// added in X.Y` comment. The comment explains why the matcher exists and which
193-
version boundary it enforces. First validate that `X.Y` is factually correct from
194-
repository or upstream evidence; do not infer it from the module name alone. Flag a
195-
missing comment in this case, and do not flag an existing one for removal unless the
196-
comment is demonstrably wrong.
197+
- **Single-class landmark comments are required.** When a single-class
198+
`hasClassesNamed(...)` check establishes the module's lower bound, add an inline
199+
`// added in X.Y` comment. If that same class also establishes the upper bound because
200+
it is removed or replaced in a newer sibling version, include that fact too, e.g.
201+
`// added in X.Y, removed in Y.Z`. First validate each stated boundary from repository
202+
or upstream evidence; do not infer versions from the module name alone. Flag a missing
203+
boundary comment in this case, and do not flag an existing dual-role comment for removal
204+
unless it is demonstrably wrong.
197205
- Prefer **one landmark class** per version boundary — choose the most stable/specific class.
198206
- Pair with **muzzle config** (`assertInverse.set(true)`) for full coverage.
199207
- Use `hasClassesNamed(...)` (from `AgentElementMatchers`) — not raw ByteBuddy matchers.

0 commit comments

Comments
 (0)