didi/DoKit · error · NullPointerException
key == null || bitmap == null
Error message
key == null || bitmap == null
What it means
LruCache.set() throws NullPointerException when either the key or the bitmap is null. Storing a null bitmap would corrupt accounting (byte sizes) and a null key could never be retrieved, so both are rejected. Fail-fast guard.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/LruCache.java:69
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");
}
Bitmap previous;
synchronized (this) {
putCount++;
size += Utils.getBitmapBytes(bitmap);
previous = map.put(key, bitmap);
if (previous != null) {
size -= Utils.getBitmapBytes(previous);
}
}
trimToSize(maxSize);
}
private void trimToSize(int maxSize) {
while (true) {
String key;View on GitHub (pinned to 626827cddb)
Solutions
- Only call set() when both key and bitmap are non-null
- Check the decode result: skip caching when the factory returned null
- Guarantee key generation (stableKey/URI/resourceId) before any cache interaction
Example fix
// before
Bitmap b = decode(data);
cache.set(key, b); // NullPointerException when b == null
// after
Bitmap b = decode(data);
if (b != null && key != null) {
cache.set(key, b);
} Defensive patterns
Strategy: validation
Validate before calling
if (key != null && bitmap != null) { cache.set(key, bitmap); } Type guard
boolean canCache(String key, Bitmap bitmap) { return key != null && bitmap != null; } Prevention
- Skip caching when a decode returns null instead of storing it
- Generate the cache key before starting the decode so it is always available
When it happens
Trigger: Calling cache.set(key, null) after a decode returned null, or cache.set(null, bitmap) when the cache key is missing.
Common situations: Caching a decode result without checking decode success; cache key derived from a URI that is null for resource-ID requests.
Related errors
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/cf34207f89081163.
Report an issue: GitHub.