{"record":{"id":"72163756623b5124","repo":"didi/DoKit","slug":"bitmap-config-must-not-be-null","errorCode":null,"errorMessage":"Bitmap config must not be null.","messagePattern":"Bitmap config must not be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java","lineNumber":713,"sourceCode":"\n    private boolean indicatorsEnabled;\n    private boolean loggingEnabled;\n\n    /** Start building a new {@link DokitPicasso} instance. */\n    public Builder(Context context) {\n      if (context == null) {\n        throw new IllegalArgumentException(\"Context must not be null.\");\n      }\n      this.context = context.getApplicationContext();\n    }\n\n    /**\n     * Specify the default {@link Bitmap.Config} used when decoding images. This can be overridden\n     * on a per-request basis using {@link RequestCreator#config(Bitmap.Config) config(..)}.\n     */\n    public Builder defaultBitmapConfig(Bitmap.Config bitmapConfig) {\n      if (bitmapConfig == null) {\n        throw new IllegalArgumentException(\"Bitmap config must not be null.\");\n      }\n      this.defaultBitmapConfig = bitmapConfig;\n      return this;\n    }\n\n    /** Specify the {@link Downloader} that will be used for downloading images. */\n    public Builder downloader(Downloader downloader) {\n      if (downloader == null) {\n        throw new IllegalArgumentException(\"Downloader must not be null.\");\n      }\n      if (this.downloader != null) {\n        throw new IllegalStateException(\"Downloader already set.\");\n      }\n      this.downloader = downloader;\n      return this;\n    }\n\n    /**","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java#L695-L731","documentation":"Builder.defaultBitmapConfig(Bitmap.Config) sets the default decode config for the whole instance (e.g. RGB_565 to halve memory). Passing null is rejected with IllegalArgumentException('Bitmap config must not be null.') because BitmapFactory.decode* with a null inPreferredConfig behaves differently across API levels — Picasso requires an explicit choice. Per-request overrides via RequestCreator.config() carry the same rule.","triggerScenarios":"Builder.defaultBitmapConfig(null) from a variable that failed to initialize; reading the config from a preference/API-gated path where the value is null on old devices (some Bitmap.Config constants are API-level specific); calling .config(null) per request.","commonSituations":"Memory-tuning code that conditionally selects ARGB_8888/RGBA_F16 and has no fallback branch; HARDWARE config used below API 26.","solutions":["Default to Bitmap.Config.ARGB_8888 when your selection logic yields null","Gate API-specific configs: use RGBA_F16/HARDWARE only on supported API levels","Remember Picasso already defaults to ARGB_8888 internally — only call this method when you actually have a config to set"],"exampleFix":"// before\nBitmap.Config cfg = prefs.getBoolean(\"lowMem\", false) ? Bitmap.Config.RGB_565 : null;\nnew DokitPicasso.Builder(context).defaultBitmapConfig(cfg).build();\n\n// after\nBitmap.Config cfg = prefs.getBoolean(\"lowMem\", false)\n    ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;\nnew DokitPicasso.Builder(context).defaultBitmapConfig(cfg).build();","handlingStrategy":"validation","validationCode":"Bitmap.Config config = lowMemory ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;\nDokitPicasso picasso = new DokitPicasso.Builder(context).defaultBitmapConfig(config).build();","typeGuard":null,"tryCatchPattern":"try {\n  builder.defaultBitmapConfig(config);\n} catch (IllegalArgumentException e) {\n  if (\"Bitmap config must not be null.\".equals(e.getMessage())) {\n    builder.defaultBitmapConfig(Bitmap.Config.ARGB_8888);\n  } else throw e;\n}","preventionTips":["Always resolve to an explicit config — default to ARGB_8888 when in doubt","Gate API-level-specific configs (HARDWARE, RGBA_F16) behind Build.VERSION checks","If you have no strong opinion, omit the call entirely; Picasso's internal default is ARGB_8888"],"tags":["android","picasso","bitmap","configuration","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}