Skip to content

Commit fad6ec5

Browse files
committed
Clarify singleton static import guidance
1 parent a38bccc commit fad6ec5

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

.github/agents/knowledge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1414
| `gradle-conventions.md` | `build.gradle.kts` or `settings.gradle.kts` changes, custom test task registration or wiring |
1515
| `javaagent-advice-patterns.md` | ByteBuddy `@Advice` class or advice-method changes |
1616
| `javaagent-module-patterns.md` | `InstrumentationModule`, `TypeInstrumentation`, `VirtualField`, `CallDepth` |
17-
| `javaagent-singletons-patterns.md` | `*Singletons` holder classes, singleton accessors, static-imported singleton callers |
17+
| `javaagent-singletons-patterns.md` | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields |
1818
| `library-patterns.md` | Library instrumentation telemetry, builder, getter, or setter pattern changes |
1919
| `module-naming.md` | New or renamed modules or packages; settings includes |
2020
| `testing-general-patterns.md` | Test files in scope — assertion style, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |

.github/agents/knowledge/general-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
2121
| Naming | Module/package naming | New or renamed modules/packages | `module-naming.md` |
2222
| Javaagent | Advice patterns | `@Advice` classes | `javaagent-advice-patterns.md` |
2323
| Javaagent | Module structure patterns | `InstrumentationModule`, `TypeInstrumentation` | `javaagent-module-patterns.md` |
24-
| Javaagent | Singletons patterns | `*Singletons` holder classes, singleton accessors, static-imported singleton callers | `javaagent-singletons-patterns.md` |
24+
| Javaagent | Singletons patterns | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields | `javaagent-singletons-patterns.md` |
2525
| Javaagent | Incorrect `classLoaderMatcher()` | `classLoaderMatcher()` override that is redundant (muzzle already handles it) or missing when needed (muzzle cannot distinguish version range) | `javaagent-module-patterns.md` |
2626
| Semconv | Library vs javaagent semconv constant usage | Semconv constants/assertions ||
2727
| Semconv | Dual semconv testing | `SemconvStability`, `maybeStable`, semconv Gradle tasks | `testing-semconv-stability.md` |

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Quick Reference
44

55
- Use when: reviewing `*Singletons` holder classes and their callers
6-
- Review focus: field/accessor naming, eager initialization, static-import call sites
6+
- Review focus: field/accessor naming, eager initialization, singleton accessor call sites
77

88
Javaagent modules keep shared `Instrumenter` instances and related collaborators in a dedicated
99
`Singletons` holder class such as `MyLibrarySingletons`.
@@ -28,10 +28,12 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
2828
- `CONTEXT` stays `CONTEXT`
2929
- `REQUEST_INFO` stays `REQUEST_INFO`
3030
- `RESPONSE_STATUS` stays `RESPONSE_STATUS`
31-
- Callers should static import the exported singleton member and use it unqualified:
32-
accessor methods for lower camel collaborators, fields for uppercase constant-like members.
31+
- Callers should static import only exported singleton accessors and uppercase constant-like
32+
fields, and use those members unqualified: accessors for lower camel collaborators, fields for
33+
uppercase constant-like members.
3334
- Keep verb-named helper methods as verbs when they perform work instead of returning a stored
34-
field. This naming rule applies to field accessors.
35+
field. These methods are not singleton accessors and should not be static imported under this
36+
rule.
3537

3638
## Preferred Pattern
3739

@@ -102,7 +104,9 @@ class MyInstrumentation implements TypeInstrumentation {
102104
and immutable value constants.
103105
- Accessor methods named `getInstrumenter()`, `getHelper()`, `getSetter()`, and similar when they
104106
simply return a backing field.
105-
- Call sites that qualify singleton member usage with the holder class instead of static importing
106-
the accessor or field.
107+
- Call sites that qualify singleton accessor or uppercase constant-like field usage with the holder
108+
class instead of static importing the accessor or field.
109+
- Static imports of non-accessor helper methods on a `*Singletons` class when the method performs
110+
work instead of returning a stored singleton or constant.
107111
- Mismatches between a field name and its accessor, such as `private static final Helper helper;`
108112
with `public static Helper getHelper()`.

0 commit comments

Comments
 (0)