{"record":{"id":"42d422be9a059021","repo":"nostra13/Android-Universal-Image-Loader","slug":"decodingoptions-can-t-be-null","errorCode":null,"errorMessage":"decodingOptions can't be null","messagePattern":"decodingOptions can't be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/DisplayImageOptions.java","lineNumber":391,"sourceCode":"\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\n\t\t/** Sets delay time before starting loading task. Default - no delay. */\n\t\tpublic Builder delayBeforeLoading(int delayInMillis) {\n\t\t\tthis.delayBeforeLoading = delayInMillis;\n\t\t\treturn this;\n\t\t}\n\n\t\t/** Sets auxiliary object which will be passed to {@link ImageDownloader#getStream(String, Object)} */\n\t\tpublic Builder extraForDownloader(Object extra) {\n\t\t\tthis.extraForDownloader = extra;\n\t\t\treturn this;\n\t\t}\n\n\t\t/** Sets whether ImageLoader will consider EXIF parameters of JPEG image (rotate, flip) */\n\t\tpublic Builder considerExifParams(boolean considerExifParams) {","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/DisplayImageOptions.java#L373-L409","documentation":"DisplayImageOptions.Builder.decodingOptions(BitmapFactory.Options) rejects a null Options object because the builder stores it and the decoders dereference it (inPreferredConfig, inSampleSize) for every image load. Note the documented caveat: the library overrides inSampleSize itself according to imageScaleType, and decodingOptions() overlaps bitmapConfig(); passing null would leave decoding undefined.","triggerScenarios":"Calling .decodingOptions(null) in an options builder chain; passing a BitmapFactory.Options field of a settings object that was never initialized; creating options lazily and forgetting the branch that leaves it null.","commonSituations":"Optional decoding settings modeled as null meaning 'default'; copy-pasted sample code where the Options variable was removed but the call stayed; proguard/stripping issues are NOT the cause here, it is always an explicit null argument.","solutions":["Pass a constructed Options: .decodingOptions(new BitmapFactory.Options())","If you only wanted the bitmap config, use .bitmapConfig(Bitmap.Config.RGB_565) instead of decodingOptions","Initialize settings fields at declaration so they can never be null"],"exampleFix":"// before\nBitmapFactory.Options o = maybeInitOptions(); // returns null by default\nbuilder.decodingOptions(o);\n\n// after\nbuilder.decodingOptions(new BitmapFactory.Options());\n// or, if only config matters:\nbuilder.bitmapConfig(Bitmap.Config.RGB_565);","handlingStrategy":"validation","validationCode":"BitmapFactory.Options o = decodingOptions != null\n        ? decodingOptions : new BitmapFactory.Options();\noptions.decodingOptions(o);","typeGuard":"static boolean isUsableDecodingOptions(BitmapFactory.Options o) {\n    return o != null;\n}","tryCatchPattern":null,"preventionTips":["Prefer the dedicated builder methods (bitmapConfig, imageScaleType) over raw Options","Initialize Options eagerly where it is declared","Remember inSampleSize is ignored — do not rely on it via decodingOptions()"],"tags":["options","builder","null-safety","bitmap-decoding"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}