{"record":{"id":"ded77b1572c6d4fd","repo":"nostra13/Android-Universal-Image-Loader","slug":"imageaware-should-wrap-imageview-imageviewaware-i-ded77b","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":"library/src/main/java/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java","lineNumber":58,"sourceCode":" */\npublic class RoundedBitmapDisplayer implements BitmapDisplayer {\n\n\tprotected final int cornerRadius;\n\tprotected final int margin;\n\n\tpublic RoundedBitmapDisplayer(int cornerRadiusPixels) {\n\t\tthis(cornerRadiusPixels, 0);\n\t}\n\n\tpublic RoundedBitmapDisplayer(int cornerRadiusPixels, int marginPixels) {\n\t\tthis.cornerRadius = cornerRadiusPixels;\n\t\tthis.margin = marginPixels;\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\n\t\timageAware.setImageDrawable(new RoundedDrawable(bitmap, cornerRadius, margin));\n\t}\n\n\tpublic static class RoundedDrawable extends Drawable {\n\n\t\tprotected final float cornerRadius;\n\t\tprotected final int margin;\n\n\t\tprotected final RectF mRect = new RectF(),\n\t\t\t\tmBitmapRect;\n\t\tprotected final BitmapShader bitmapShader;\n\t\tprotected final Paint paint;\n\n\t\tpublic RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {\n\t\t\tthis.cornerRadius = cornerRadius;\n\t\t\tthis.margin = margin;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java#L40-L76","documentation":"RoundedBitmapDisplayer.display() requires an ImageViewAware target because RoundedDrawable must be attached to an ImageView through setImageDrawable. Any other ImageAware implementation triggers IllegalArgumentException at display time, after the bitmap has already been downloaded and decoded. The check exists because rounded corners are a view-level visual effect that only an ImageView-backed aware can render.","triggerScenarios":"Using .displayer(new RoundedBitmapDisplayer(radius, margin)) in DisplayImageOptions and then calling displayImage with a NonViewAware, a custom ImageAware subclass, or an aware wrapping a non-ImageView View. Also hit when the same DisplayImageOptions instance (built for a list of ImageViews) is reused for a non-view prefetch call.","commonSituations":"Reusing one global DisplayImageOptions object across both ImageView loading and background prefetching; upgrading old code that used ImageLoadingListener-onLoadingComplete with ImageAware; copying the 'rounded corners' sample into a ViewHolder that wraps views in custom awares.","solutions":["Use an ImageViewAware (or pass the ImageView directly) as the target when rounded corners are enabled","For prefetch/processing-only loads, use a separate DisplayImageOptions without the displayer","Write a custom displayer if you must apply rounding to a non-ImageView target"],"exampleFix":"// before\nDisplayImageOptions opts = new DisplayImageOptions.Builder()\n        .displayer(new RoundedBitmapDisplayer(20))\n        .build();\nimageLoader.displayImage(uri, new NonViewAware(uri, size, ViewScaleType.CROP), opts);\n\n// after\nDisplayImageOptions roundedOpts = new DisplayImageOptions.Builder()\n        .displayer(new RoundedBitmapDisplayer(20))\n        .build();\nimageLoader.displayImage(uri, imageView, roundedOpts);","handlingStrategy":"type-guard","validationCode":"boolean isViewTarget = aware instanceof ImageViewAware;\nDisplayImageOptions opts = isViewTarget ? roundedOptions : plainOptions;\nimageLoader.displayImage(uri, aware, opts);","typeGuard":"private static boolean supportsDisplayer(ImageAware aware, BitmapDisplayer displayer) {\n    return !(displayer instanceof RoundedBitmapDisplayer) || aware instanceof ImageViewAware;\n}","tryCatchPattern":null,"preventionTips":["Name option constants by purpose (OPTS_IMAGEVIEW_ROUNDED vs OPTS_PREFETCH) so misuse is visible in review","Audit any shared options builder for displayers before reusing it with NonViewAware"],"tags":["universal-image-loader","displayer","rounded-corners","imageview"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}