{"record":{"id":"9905a57b37fc0e53","repo":"nostra13/Android-Universal-Image-Loader","slug":"imageaware-should-wrap-imageview-imageviewaware-i-9905a5","errorCode":null,"errorMessage":"ImageAware should wrap ImageView. ImageViewAware is expected.","messagePattern":"ImageAware should wrap ImageView\\. ImageViewAware is expected\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sample/src/main/java/com/nostra13/universalimageloader/sample/ext/OldRoundedBitmapDisplayer.java","lineNumber":53,"sourceCode":" * <b>NOTE:</b> It's strongly recommended your {@link ImageView} has defined width (<i>layout_width</i>) and height\n * (<i>layout_height</i>) .<br />\n * <b>NOTE:</b> New {@link Bitmap} object is created for displaying. So this class needs more memory and can cause\n * {@link OutOfMemoryError}.\n *\n * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)\n */\npublic class OldRoundedBitmapDisplayer implements BitmapDisplayer {\n\n\tprivate final int roundPixels;\n\n\tpublic OldRoundedBitmapDisplayer(int roundPixels) {\n\t\tthis.roundPixels = roundPixels;\n\t}\n\n\t@Override\n\tpublic void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {\n\t\tif (!(imageAware instanceof ImageViewAware)) {\n\t\t\tthrow new IllegalArgumentException(\"ImageAware should wrap ImageView. ImageViewAware is expected.\");\n\t\t}\n\t\tBitmap roundedBitmap = roundCorners(bitmap, (ImageViewAware) imageAware, roundPixels);\n\t\timageAware.setImageBitmap(roundedBitmap);\n\t}\n\n\t/**\n\t * Process incoming {@linkplain Bitmap} to make rounded corners according to target\n\t * {@link com.nostra13.universalimageloader.core.imageaware.ImageViewAware}.<br />\n\t * This method <b>doesn't display</b> result bitmap in {@link ImageView}\n\t *\n\t * @param bitmap      Incoming Bitmap to process\n\t * @param imageAware  Target {@link com.nostra13.universalimageloader.core.imageaware.ImageAware ImageAware} to\n\t *                    display bitmap in\n\t * @param roundPixels Rounded pixels of corner\n\t * @return Result bitmap with rounded corners\n\t */\n\tpublic static Bitmap roundCorners(Bitmap bitmap, ImageViewAware imageAware, int roundPixels) {\n\t\tImageView imageView = imageAware.getWrappedView();","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/sample/src/main/java/com/nostra13/universalimageloader/sample/ext/OldRoundedBitmapDisplayer.java#L35-L71","documentation":"OldRoundedBitmapDisplayer is the sample app's legacy rounded-corner displayer; like the library's RoundedBitmapDisplayer it requires an ImageViewAware target and throws IllegalArgumentException otherwise, because roundCorners() needs the ImageView's dimensions and the result is set via setImageBitmap on the view. It exists in the sample (sample/src/.../ext/) to demonstrate a pre-1.9 displayer implementation.","triggerScenarios":"Applying OldRoundedBitmapDisplayer through DisplayImageOptions while displaying into a NonViewAware or custom ImageAware; copying this sample class into app code and using it with loadImage(uri, targetSize, listener)-style flows that build NonViewAware internally.","commonSituations":"Copy-pasting sample code into production; keeping pre-1.9 displayer implementations alive after migrating to ImageAware-based APIs; using the sample's 'old rounded corners' option against non-view targets.","solutions":["Use an ImageViewAware/ImageView target with this displayer","Replace it with the library's RoundedBitmapDisplayer (same behavior, maintained, supports margin) — while still targeting an ImageView","For non-view processing, drop the displayer and apply rounding manually on the returned bitmap"],"exampleFix":"// before\nimageLoader.displayImage(uri, nonViewAware,\n        new DisplayImageOptions.Builder().displayer(new OldRoundedBitmapDisplayer(16)).build());\n\n// after\nimageLoader.displayImage(uri, imageView,\n        new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(16)).build());","handlingStrategy":"type-guard","validationCode":"if (aware instanceof ImageViewAware) {\n    imageLoader.displayImage(uri, aware, oldRoundedOptions);\n} else {\n    imageLoader.displayImage(uri, aware, plainOptions);\n}","typeGuard":"private static boolean canUseOldRounded(ImageAware aware, DisplayImageOptions opts) {\n    return !(opts.getDisplayer() instanceof OldRoundedBitmapDisplayer)\n            || aware instanceof ImageViewAware;\n}","tryCatchPattern":null,"preventionTips":["Treat sample/ext classes as references, not production dependencies — prefer the library's RoundedBitmapDisplayer","Apply the same 'displayer implies ImageViewAware' rule to any custom BitmapDisplayer you write"],"tags":["universal-image-loader","sample","displayer","rounded-corners","legacy"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}