Skip to content

Commit 49df437

Browse files
committed
doc
1 parent 385f404 commit 49df437

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
2222
- `helper` -> `helper()`
2323
- `setter` -> `setter()`
2424
- For exported uppercase constant-like fields that represent stable identifiers, immutable
25-
descriptors, or semantic keys/handles such as `VirtualField` and `ContextKey`, it is acceptable
26-
to expose them as `public static final` fields with no accessor.
25+
descriptors, semantic keys/handles such as `VirtualField` and `ContextKey`, or immutable value
26+
constants such as strings, booleans, and fixed timeout/interval values, it is acceptable to
27+
expose them as `public static final` fields with no accessor.
2728
- `CONTEXT` stays `CONTEXT`
2829
- `REQUEST_INFO` stays `REQUEST_INFO`
2930
- `RESPONSE_STATUS` stays `RESPONSE_STATUS`
@@ -35,7 +36,7 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
3536
## Preferred Pattern
3637

3738
```java
38-
public final class MyLibrarySingletons {
39+
public class MyLibrarySingletons {
3940

4041
private static final Instrumenter<Request, Response> instrumenter =
4142
JavaagentHttpServerInstrumenters.create(...);
@@ -57,7 +58,7 @@ public final class MyLibrarySingletons {
5758
Uppercase field exception:
5859

5960
```java
60-
public final class MyLibrarySingletons {
61+
public class MyLibrarySingletons {
6162

6263
public static final VirtualField<Request, Context> REQUEST_CONTEXT =
6364
VirtualField.find(Request.class, Context.class);
@@ -96,8 +97,9 @@ class MyInstrumentation implements TypeInstrumentation {
9697
## What to Flag in Review
9798

9899
- Exposed lower camel collaborator fields such as `public static final Instrumenter ...`.
99-
- Private + accessor wrappers around uppercase semantic keys/handles when a direct `public static
100-
final` field would be clearer and matches the naming guidance.
100+
- Private + accessor wrappers around uppercase constant-like fields when a direct `public static
101+
final` field would be clearer and matches the naming guidance, including semantic keys/handles
102+
and immutable value constants.
101103
- Accessor methods named `getInstrumenter()`, `getHelper()`, `getSetter()`, and similar when they
102104
simply return a backing field.
103105
- Call sites that qualify singleton member usage with the holder class instead of static importing

0 commit comments

Comments
 (0)