didi/DoKit · error · NullPointerException
key == null
Error message
key == null
What it means
LruCache.get() throws NullPointerException when the key is null. Cache keys are strings (usually request URLs or stable keys) and null can never match an entry, so the cache rejects it immediately rather than returning a miss.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/LruCache.java:51
private int missCount;
/** Create a cache using an appropriate portion of the available RAM as the maximum size. */
public LruCache(Context context) {
this(Utils.calculateMemoryCacheSize(context));
}
/** Create a cache with a given maximum size in bytes. */
public LruCache(int maxSize) {
if (maxSize <= 0) {
throw new IllegalArgumentException("Max size must be positive.");
}
this.maxSize = maxSize;
this.map = new LinkedHashMap<String, Bitmap>(0, 0.75f, true);
}
@Override public Bitmap get(String key) {
if (key == null) {
throw new NullPointerException("key == null");
}
Bitmap mapValue;
synchronized (this) {
mapValue = map.get(key);
if (mapValue != null) {
hitCount++;
return mapValue;
}
missCount++;
}
return null;
}
@Override public void set(String key, Bitmap bitmap) {
if (key == null || bitmap == null) {
throw new NullPointerException("key == null || bitmap == null");View on GitHub (pinned to 626827cddb)
Solutions
- Null-check the key before calling get() and treat null as a cache miss (return null / skip cache)
- Fix the request construction so a valid key (URI, resourceId, or stableKey) always exists
- Validate external string inputs at the boundary before they reach the cache
Example fix
// before cache.get(url); // NullPointerException when url == null // after Bitmap hit = url == null ? null : cache.get(url);
Defensive patterns
Strategy: validation
Validate before calling
Bitmap hit = (key == null) ? null : cache.get(key);
Type guard
boolean isValidCacheKey(String key) { return key != null && key.length() > 0; } Prevention
- Validate external string inputs before they become cache keys
- Ensure every request carries a URI, resourceId, or stableKey
When it happens
Trigger: Calling cache.get(null), typically because a URL or stableKey field was null upstream; or a Map lookup with a missing key whose result was passed through.
Common situations: Requests built without a URI or resourceId so the cache key computes to null; passing an unvalidated external string (intent extra, deep link) straight into the cache.
Related errors
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/71715d36753e4740.
Report an issue: GitHub.