Skip to content

Commit 778953c

Browse files
dougqhclaude
andcommitted
Address review feedback
- Restore refreshAcessTime as a deprecated forwarding alias to preserve binary compatibility for any existing callers compiled against the prior artifact. - Drop reflection in GenerationalUtf8CacheTest by making the eden and tenured entry arrays package-visible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dd77994 commit 778953c

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

communication/src/main/java/datadog/communication/serialization/GenerationalUtf8Cache.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ public final class GenerationalUtf8Cache implements EncodingCache {
8585

8686
static final int MAX_ENTRY_LEN = 256;
8787

88-
private final CacheEntry[] edenEntries;
88+
final CacheEntry[] edenEntries;
8989
private final int[] edenMarkers;
9090

91-
private final CacheEntry[] tenuredEntries;
91+
final CacheEntry[] tenuredEntries;
9292

9393
private long accessTimeMs;
9494
private double promotionThreshold = INITIAL_PROMOTION_THRESHOLD;
@@ -147,6 +147,12 @@ public void refreshAccessTime() {
147147
this.updateAccessTime(System.currentTimeMillis());
148148
}
149149

150+
/** Deprecated in favor of {@link #refreshAccessTime()} - retained for binary compatibility. */
151+
@Deprecated
152+
public void refreshAcessTime() {
153+
this.refreshAccessTime();
154+
}
155+
150156
public synchronized void recalibrate() {
151157
this.recalibrate(System.currentTimeMillis());
152158
}

communication/src/test/java/datadog/communication/serialization/GenerationalUtf8CacheTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static org.junit.jupiter.api.Assertions.assertNotSame;
77
import static org.junit.jupiter.api.Assertions.assertSame;
88

9-
import java.lang.reflect.Field;
109
import java.nio.charset.StandardCharsets;
1110
import java.util.Random;
1211
import java.util.concurrent.ThreadLocalRandom;
@@ -91,7 +90,7 @@ public void caching() {
9190
}
9291

9392
@Test
94-
public void getUtf8_perCallAccessTime_overridesField() throws Exception {
93+
public void getUtf8_perCallAccessTime_overridesField() {
9594
GenerationalUtf8Cache cache = create();
9695
// The field value should not leak into the entry when an explicit time is supplied.
9796
cache.updateAccessTime(0L);
@@ -236,27 +235,22 @@ static final String nextValue() {
236235
return baseString + valueSuffix;
237236
}
238237

239-
static long lookupEdenLastUsedMs(GenerationalUtf8Cache cache, String value) throws Exception {
240-
return lookupLastUsedMs(cache, "edenEntries", value);
238+
static long lookupEdenLastUsedMs(GenerationalUtf8Cache cache, String value) {
239+
return lookupLastUsedMs(cache.edenEntries, "edenEntries", value);
241240
}
242241

243-
static long lookupTenuredLastUsedMs(GenerationalUtf8Cache cache, String value) throws Exception {
244-
return lookupLastUsedMs(cache, "tenuredEntries", value);
242+
static long lookupTenuredLastUsedMs(GenerationalUtf8Cache cache, String value) {
243+
return lookupLastUsedMs(cache.tenuredEntries, "tenuredEntries", value);
245244
}
246245

247-
private static long lookupLastUsedMs(GenerationalUtf8Cache cache, String fieldName, String value)
248-
throws Exception {
249-
Field arrayField = GenerationalUtf8Cache.class.getDeclaredField(fieldName);
250-
arrayField.setAccessible(true);
251-
GenerationalUtf8Cache.CacheEntry[] entries =
252-
(GenerationalUtf8Cache.CacheEntry[]) arrayField.get(cache);
253-
246+
private static long lookupLastUsedMs(
247+
GenerationalUtf8Cache.CacheEntry[] entries, String arrayName, String value) {
254248
for (GenerationalUtf8Cache.CacheEntry entry : entries) {
255249
if (entry != null && value.equals(entry.value)) {
256250
return entry.lastUsedMs();
257251
}
258252
}
259-
throw new AssertionError("entry for value '" + value + "' not found in " + fieldName);
253+
throw new AssertionError("entry for value '" + value + "' not found in " + arrayName);
260254
}
261255

262256
static final void printStats(GenerationalUtf8Cache cache) {

0 commit comments

Comments
 (0)