nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException
imageSize must not be null
Error message
imageSize must not be null
What it means
NonViewAware's constructor rejects a null ImageSize with IllegalArgumentException because every subsequent call (getWidth, getHeight, scaleType computations) dereferences it — the target size IS the whole point of a view-less ImageAware. It also rejects null ViewScaleType for the same reason. Failing fast here prevents an NPE deep inside the resize/decode pipeline.
Source
Thrown at library/src/main/java/com/nostra13/universalimageloader/core/imageaware/NonViewAware.java:45
* used when user need just load and decode image and get it in {@linkplain
* com.nostra13.universalimageloader.core.listener.ImageLoadingListener#onLoadingComplete(String, android.view.View,
* android.graphics.Bitmap) callback}.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.9.0
*/
public class NonViewAware implements ImageAware {
protected final String imageUri;
protected final ImageSize imageSize;
protected final ViewScaleType scaleType;
public NonViewAware(ImageSize imageSize, ViewScaleType scaleType) {
this(null, imageSize, scaleType);
}
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) {
if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null");
if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null");
this.imageUri = imageUri;
this.imageSize = imageSize;
this.scaleType = scaleType;
}
@Override
public int getWidth() {
return imageSize.getWidth();
}
@Override
public int getHeight() {
return imageSize.getHeight();
}
@OverrideView on GitHub (pinned to ba33ec64d0)
Solutions
- Compute a concrete ImageSize before constructing (e.g. new ImageSize(200, 200) or ImageSizeUtils.sizeToDecodeBounds)
- Null-check any dynamically produced ImageSize and substitute a default rather than passing null
- If you have no meaningful size, derive one from configuration (maxImageBounds) or your layout constraints
- Also ensure scaleType is non-null — the same guard covers it
Example fix
// before ImageSize size = parseSizeFromIntent(intent); // may return null NonViewAware aware = new NonViewAware(uri, size, ViewScaleType.CROP); // after ImageSize size = parseSizeFromIntent(intent); if (size == null) size = new ImageSize(256, 256); NonViewAware aware = new NonViewAware(uri, size, ViewScaleType.CROP);
Defensive patterns
Strategy: validation
Validate before calling
ImageSize size = resolveSize(); // may be null if (size == null) size = new ImageSize(256, 256); ViewScaleType st = (scaleType != null) ? scaleType : ViewScaleType.CROP; NonViewAware aware = new NonViewAware(uri, size, st);
Type guard
private static boolean isNonViewAwareInputValid(ImageSize size, ViewScaleType st) {
return size != null && st != null;
} Prevention
- Treat ImageSize and ViewScaleType as required fields of any prefetch request object; validate at request construction
- Provide a default size constant instead of propagating null from parsers
- Add @NonNull-style annotations or Objects.requireNonNull at the call site for clearer stack traces
When it happens
Trigger: new NonViewAware(null, ViewScaleType.CROP) via the two-arg constructor, or new NonViewAware(uri, null, scaleType); building the ImageSize lazily after construction; passing a size obtained from a not-yet-laid-out view (e.g. getWidth()==0 is fine, but a null from a helper method is not).
Common situations: Prefetching images for widgets/notifications where no view exists; helper methods returning null on parse failure feeding the constructor; refactoring ViewAware code into NonViewAware and dropping the size argument.
Related errors
- view must not be null
- cacheDir argument must be not null
- fileNameGenerator argument must be not null
- cacheDir argument must be not null
- fileNameGenerator argument must be not null
AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14).
Data as JSON: /api/errors/afc7e5d503faee5c.
Report an issue: GitHub.