{"record":{"id":"71715d36753e4740","repo":"didi/DoKit","slug":"key-null","errorCode":null,"errorMessage":"key == null","messagePattern":"key == null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/LruCache.java","lineNumber":51,"sourceCode":"  private int missCount;\n\n  /** Create a cache using an appropriate portion of the available RAM as the maximum size. */\n  public LruCache(Context context) {\n    this(Utils.calculateMemoryCacheSize(context));\n  }\n\n  /** Create a cache with a given maximum size in bytes. */\n  public LruCache(int maxSize) {\n    if (maxSize <= 0) {\n      throw new IllegalArgumentException(\"Max size must be positive.\");\n    }\n    this.maxSize = maxSize;\n    this.map = new LinkedHashMap<String, Bitmap>(0, 0.75f, true);\n  }\n\n  @Override public Bitmap get(String key) {\n    if (key == null) {\n      throw new NullPointerException(\"key == null\");\n    }\n\n    Bitmap mapValue;\n    synchronized (this) {\n      mapValue = map.get(key);\n      if (mapValue != null) {\n        hitCount++;\n        return mapValue;\n      }\n      missCount++;\n    }\n\n    return null;\n  }\n\n  @Override public void set(String key, Bitmap bitmap) {\n    if (key == null || bitmap == null) {\n      throw new NullPointerException(\"key == null || bitmap == null\");","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/LruCache.java#L33-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ncache.get(url); // NullPointerException when url == null\n\n// after\nBitmap hit = url == null ? null : cache.get(url);","handlingStrategy":"validation","validationCode":"Bitmap hit = (key == null) ? null : cache.get(key);","typeGuard":"boolean isValidCacheKey(String key) { return key != null && key.length() > 0; }","tryCatchPattern":null,"preventionTips":["Validate external string inputs before they become cache keys","Ensure every request carries a URI, resourceId, or stableKey"],"tags":["android","picasso","cache","null-check"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}