{"record":{"id":"b6e641d50f774b23","repo":"nostra13/Android-Universal-Image-Loader","slug":"bitmapconfig-can-t-be-null","errorCode":null,"errorMessage":"bitmapConfig can't be null","messagePattern":"bitmapConfig can't be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/DisplayImageOptions.java","lineNumber":377,"sourceCode":"\n\t\t/** Sets whether loaded image will be cached on disk */\n\t\tpublic Builder cacheOnDisk(boolean cacheOnDisk) {\n\t\t\tthis.cacheOnDisk = cacheOnDisk;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Sets {@linkplain ImageScaleType scale type} for decoding image. This parameter is used while define scale\n\t\t * size for decoding image to Bitmap. Default value - {@link ImageScaleType#IN_SAMPLE_POWER_OF_2}\n\t\t */\n\t\tpublic Builder imageScaleType(ImageScaleType imageScaleType) {\n\t\t\tthis.imageScaleType = imageScaleType;\n\t\t\treturn this;\n\t\t}\n\n\t\t/** Sets {@link Bitmap.Config bitmap config} for image decoding. Default value - {@link Bitmap.Config#ARGB_8888} */\n\t\tpublic Builder bitmapConfig(Bitmap.Config bitmapConfig) {\n\t\t\tif (bitmapConfig == null) throw new IllegalArgumentException(\"bitmapConfig can't be null\");\n\t\t\tdecodingOptions.inPreferredConfig = bitmapConfig;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Sets options for image decoding.<br />\n\t\t * <b>NOTE:</b> {@link Options#inSampleSize} of incoming options will <b>NOT</b> be considered. Library\n\t\t * calculate the most appropriate sample size itself according yo {@link #imageScaleType(ImageScaleType)}\n\t\t * options.<br />\n\t\t * <b>NOTE:</b> This option overlaps {@link #bitmapConfig(android.graphics.Bitmap.Config) bitmapConfig()}\n\t\t * option.\n\t\t */\n\t\tpublic Builder decodingOptions(Options decodingOptions) {\n\t\t\tif (decodingOptions == null) throw new IllegalArgumentException(\"decodingOptions can't be null\");\n\t\t\tthis.decodingOptions = decodingOptions;\n\t\t\treturn this;\n\t\t}\n","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/DisplayImageOptions.java#L359-L395","documentation":"DisplayImageOptions.Builder.bitmapConfig(Bitmap.Config) rejects null because the value is written directly into the BitmapFactory.Options instance (decodingOptions.inPreferredConfig) that is reused for every decode; a null there would defeat the whole builder chain and crash later at decode time with a less clear error. Only real configs (ALPHA_8, RGB_565, ARGB_8888) are accepted.","triggerScenarios":"Calling .bitmapConfig(null) in a DisplayImageOptions.Builder chain, usually when reading the config from a variable/JSON setting that was never populated; conditional code like config.useHighQuality ? ARGB_8888 : null.","commonSituations":"Quality toggles implemented as 'high quality or null'; deserializing a user preference where an unknown enum string maps to null; refactors that made the field @Nullable but kept the direct pass-through.","solutions":["Default the variable: config = (config != null) ? config : Bitmap.Config.ARGB_8888","Model quality as an explicit choice: ARGB_8888 for quality, RGB_565 for memory, never null","Delete the branch that can produce null (e.g. replace ternary with a two-branch if/else)"],"exampleFix":"// before\nBitmap.Config cfg = prefs.getBoolean(\"hq\") ? Bitmap.Config.ARGB_8888 : null;\noptions.bitmapConfig(cfg); // throws bitmapConfig can't be null\n\n// after\nBitmap.Config cfg = prefs.getBoolean(\"hq\") ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;\noptions.bitmapConfig(cfg);","handlingStrategy":"validation","validationCode":"Bitmap.Config cfg = (chosenConfig != null) ? chosenConfig : Bitmap.Config.ARGB_8888;\noptions.bitmapConfig(cfg);","typeGuard":"static boolean isValidBitmapConfig(Bitmap.Config c) {\n    return c != null; // ALPHA_8, RGB_565, ARGB_8888 are the meaningful values\n}","tryCatchPattern":null,"preventionTips":["Model bitmap quality as an explicit enum choice, never nullable","Default settings fields to ARGB_8888 at declaration","Use RGB_565 for memory-heavy lists instead of 'null means cheap'"],"tags":["options","builder","null-safety","bitmap-decoding"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}