$ show alibaba/java-dns-cache-manipulator
Java Dns Cache Manipulator (DCM) is a small, zero-dependency library and accompanying CLI tool for programmatically setting, viewing, and clearing the JVM's DNS cache without modifying the hosts file. It works by using reflection to access private fields of `java.net.InetAddress` and `sun.net.InetAddressCachePolicy`. The library handles both pre-JDK 9 (old `InetAddress.CacheEntry` model) and JDK 9+ (new `CachedAddresses`/`CachedLookup` model), making it compatible with JDK 8 through 26. The tool module uses the Java Attach API to inject a Java agent into a running JVM process to execute commands like get, set, remove, list, or clear DNS cache entries. The code is well-structured with clear separation between API, internal implementation, agent, and tool modules. It is thread-safe, immutable value objects (DnsCacheEntry, DnsCache) are used, and extensive Kotlin-based tests ensure correctness across multiple JDK versions.
The LLM identified 1 files worth highlighting for reuse:
Handles DNS cache manipulation for JDK 9+ using reflection to access InetAddress.CachedAddresses (later renamed CachedLookup). Uses double-checked locking for lazy initialization of reflective fields and constructors. The pattern of isolating JDK-version-specific internal API access into a dedicated utility class, with a common interface, is highly reusable for any library that must work across multiple JDK versions with different private internal structures.