{"record":{"id":"0112f3b80614ff90","repo":"nostra13/Android-Universal-Image-Loader","slug":"imageaware-should-wrap-imageview-imageviewaware-i","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/CircleBitmapDisplayer.java","lineNumber":66,"sourceCode":"\tprotected final float strokeWidth;\n\n\tpublic CircleBitmapDisplayer() {\n\t\tthis(null);\n\t}\n\n\tpublic CircleBitmapDisplayer(Integer strokeColor) {\n\t\tthis(strokeColor, 0);\n\t}\n\n\tpublic CircleBitmapDisplayer(Integer strokeColor, float strokeWidth) {\n\t\tthis.strokeColor = strokeColor;\n\t\tthis.strokeWidth = strokeWidth;\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 CircleDrawable(bitmap, strokeColor, strokeWidth));\n\t}\n\n\tpublic static class CircleDrawable extends Drawable {\n\n\t\tprotected float radius;\n\n\t\tprotected final RectF mRect = new RectF();\n\t\tprotected final RectF mBitmapRect;\n\t\tprotected final BitmapShader bitmapShader;\n\t\tprotected final Paint paint;\n\t\tprotected final Paint strokePaint;\n\t\tprotected final float strokeWidth;\n\t\tprotected float strokeRadius;\n\n\t\tpublic CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/display/CircleBitmapDisplayer.java#L48-L84","documentation":"CircleBitmapDisplayer.display() requires the ImageAware it receives to be an instance of ImageViewAware, because the resulting CircleDrawable is set via setImageDrawable on an ImageView-backed aware. The library throws IllegalArgumentException when any other ImageAware implementation (e.g. NonViewAware) is passed, since a circular clip only makes sense on a real ImageView target. This is a programming/configuration error, not a runtime data error.","triggerScenarios":"Calling ImageLoader.displayImage(uri, aware, options) where options.displayer(new CircleBitmapDisplayer(...)) and 'aware' is a NonViewAware, a custom ImageAware, or any wrapper that does not extend ImageViewAware. Also occurs if you build your own ImageAware around a non-ImageView View and use this displayer.","commonSituations":"Developers migrating from Old Universal Image Loader samples where displayers were applied blindly; using NonViewAware to prefetch/process bitmaps while reusing display options configured for ImageView targets; passing a custom ImageAware for widget targets (e.g. RemoteViews-based) with a circle displayer attached.","solutions":["Pass an ImageViewAware (or just the ImageView itself — displayImage(ImageView, ...) wraps it automatically) when using CircleBitmapDisplayer","If you only need the processed bitmap (no view), remove the displayer from options and do the circular transformation yourself","If you target a non-View surface, implement a custom BitmapDisplayer that skips the instanceof check and consumes the bitmap directly"],"exampleFix":"// before\nImageAware aware = new NonViewAware(uri, new ImageSize(200, 200), ViewScaleType.CROP);\nimageLoader.displayImage(uri, aware, new DisplayImageOptions.Builder()\n        .displayer(new CircleBitmapDisplayer(Color.WHITE, 3))\n        .build());\n\n// after\nImageView imageView = (ImageView) findViewById(R.id.avatar);\nimageLoader.displayImage(uri, imageView, new DisplayImageOptions.Builder()\n        .displayer(new CircleBitmapDisplayer(Color.WHITE, 3))\n        .build());","handlingStrategy":"type-guard","validationCode":"if (aware instanceof ImageViewAware) {\n    imageLoader.displayImage(uri, aware, optionsWithCircleDisplayer);\n} else {\n    imageLoader.displayImage(uri, aware, optionsWithoutDisplayer);\n}","typeGuard":"private static boolean canDisplay(BitmapDisplayer d, ImageAware a) {\n    return !(d instanceof CircleBitmapDisplayer) || a instanceof ImageViewAware;\n}","tryCatchPattern":null,"preventionTips":["Keep one DisplayImageOptions per target kind: a 'view' variant with displayers and a 'plain' variant for NonViewAware","Centralize displayImage calls in one helper that chooses options based on 'instanceof ImageViewAware'","Never reuse list-adapter options for prefetch jobs"],"tags":["universal-image-loader","displayer","imageview","validation"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}