Skip to content

Commit b917792

Browse files
dougqhclaude
andcommitted
Mark tag keys @nonnull on the TagMap write/create surface
A tag has no valid null key, so put/set/getAndSet/create now take @nonnull tag. This completes the null contract alongside the value/Entry side: keys are strict (null = a bug), values/Entries on the Entry pathway are tolerant (null = no tag). Scoped to the write/create surface; read/lookup keys (getString, remove, getXxxOrDefault) are left for a possible follow-up. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fc7bc19 commit b917792

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

  • internal-api/src/main/java/datadog/trace/api

internal-api/src/main/java/datadog/trace/api/TagMap.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,45 +149,45 @@ static Ledger ledger(int size) {
149149
* are implemented more efficiently.
150150
*/
151151
@Deprecated
152-
Object put(String tag, Object value);
152+
Object put(@Nonnull String tag, Object value);
153153

154154
/** Sets value without returning prior value - more efficient than {@link Map#put} */
155-
void set(String tag, @Nonnull Object value);
155+
void set(@Nonnull String tag, @Nonnull Object value);
156156

157157
/**
158158
* Similar to {@link TagMap#set(String, Object)} but more efficient when working with
159159
* CharSequences and Strings. Depending on this situation, this methods avoids having to do type
160160
* resolution later on
161161
*/
162-
void set(String tag, @Nonnull CharSequence value);
162+
void set(@Nonnull String tag, @Nonnull CharSequence value);
163163

164-
void set(String tag, boolean value);
164+
void set(@Nonnull String tag, boolean value);
165165

166-
void set(String tag, int value);
166+
void set(@Nonnull String tag, int value);
167167

168-
void set(String tag, long value);
168+
void set(@Nonnull String tag, long value);
169169

170-
void set(String tag, float value);
170+
void set(@Nonnull String tag, float value);
171171

172-
void set(String tag, double value);
172+
void set(@Nonnull String tag, double value);
173173

174174
/** A null reader is a no-op (see the null-tolerance contract on {@link #getAndSet(Entry)}). */
175175
void set(@Nullable EntryReader newEntry);
176176

177177
/** sets the value while returning the prior Entry */
178-
Entry getAndSet(String tag, Object value);
178+
Entry getAndSet(@Nonnull String tag, Object value);
179179

180-
Entry getAndSet(String tag, CharSequence value);
180+
Entry getAndSet(@Nonnull String tag, CharSequence value);
181181

182-
Entry getAndSet(String tag, boolean value);
182+
Entry getAndSet(@Nonnull String tag, boolean value);
183183

184-
Entry getAndSet(String tag, int value);
184+
Entry getAndSet(@Nonnull String tag, int value);
185185

186-
Entry getAndSet(String tag, long value);
186+
Entry getAndSet(@Nonnull String tag, long value);
187187

188-
Entry getAndSet(String tag, float value);
188+
Entry getAndSet(@Nonnull String tag, float value);
189189

190-
Entry getAndSet(String tag, double value);
190+
Entry getAndSet(@Nonnull String tag, double value);
191191

192192
/**
193193
* Places an Entry directly into the map, avoiding a new Entry allocation. Null-tolerant: a null
@@ -379,39 +379,39 @@ final class Entry extends EntryChange implements Map.Entry<String, Object>, Entr
379379
* the same as via the {@link #create(String, CharSequence)} overload.
380380
*/
381381
@Nullable
382-
public static final Entry create(String tag, Object value) {
382+
public static final Entry create(@Nonnull String tag, Object value) {
383383
if (value == null) return null;
384384
if (value instanceof CharSequence && ((CharSequence) value).length() == 0) return null;
385385
return TagMap.Entry.newAnyEntry(tag, value);
386386
}
387387

388388
/** If value is non-null, returns a new TagMap.Entry If value is null or empty, returns null */
389389
@Nullable
390-
public static final Entry create(String tag, CharSequence value) {
390+
public static final Entry create(@Nonnull String tag, CharSequence value) {
391391
// NOTE: From the static typing, we know that value is not a primitive box
392392

393393
return (value == null || value.length() == 0)
394394
? null
395395
: TagMap.Entry.newObjectEntry(tag, value);
396396
}
397397

398-
public static final Entry create(String tag, boolean value) {
398+
public static final Entry create(@Nonnull String tag, boolean value) {
399399
return TagMap.Entry.newBooleanEntry(tag, value);
400400
}
401401

402-
public static final Entry create(String tag, int value) {
402+
public static final Entry create(@Nonnull String tag, int value) {
403403
return TagMap.Entry.newIntEntry(tag, value);
404404
}
405405

406-
public static final Entry create(String tag, long value) {
406+
public static final Entry create(@Nonnull String tag, long value) {
407407
return TagMap.Entry.newLongEntry(tag, value);
408408
}
409409

410-
public static final Entry create(String tag, float value) {
410+
public static final Entry create(@Nonnull String tag, float value) {
411411
return TagMap.Entry.newFloatEntry(tag, value);
412412
}
413413

414-
public static final Entry create(String tag, double value) {
414+
public static final Entry create(@Nonnull String tag, double value) {
415415
return TagMap.Entry.newDoubleEntry(tag, value);
416416
}
417417

0 commit comments

Comments
 (0)