bumptech/glide · error · IllegalArgumentException
Cannot round with null rounding
Error message
Cannot round with null rounding
What it means
Thrown by Downsampler when DownsampleStrategy.getSampleSizeRounding() returns null. SampleSizeRounding tells Glide whether to round the sample size up (QUALITY) or down (MEMORY) for the BitmapFactory; null is treated as an invalid strategy state.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java:570
+ " from: "
+ downsampleStrategy
+ ", source: ["
+ sourceWidth
+ "x"
+ sourceHeight
+ "]"
+ ", target: ["
+ targetWidth
+ "x"
+ targetHeight
+ "]");
}
SampleSizeRounding rounding =
downsampleStrategy.getSampleSizeRounding(
orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight);
if (rounding == null) {
throw new IllegalArgumentException("Cannot round with null rounding");
}
int outWidth = round(exactScaleFactor * orientedSourceWidth);
int outHeight = round(exactScaleFactor * orientedSourceHeight);
int widthScaleFactor = orientedSourceWidth / outWidth;
int heightScaleFactor = orientedSourceHeight / outHeight;
// TODO: This isn't really right for both CenterOutside and CenterInside. Consider allowing
// DownsampleStrategy to pick, or trying to do something more sophisticated like picking the
// scale factor that leads to an exact match.
int scaleFactor =
rounding == SampleSizeRounding.MEMORY
? Math.max(widthScaleFactor, heightScaleFactor)
: Math.min(widthScaleFactor, heightScaleFactor);
int powerOfTwoSampleSize;
// BitmapFactory does not support downsampling wbmp files on platforms <= M. See b/27305903.View on GitHub (pinned to eb14a895d8)
Solutions
- In your custom DownsampleStrategy, always return SampleSizeRounding.QUALITY or SampleSizeRounding.MEMORY from getSampleSizeRounding.
- Delegate to an existing strategy (DownsampleStrategy.DEFAULT) for edge cases instead of returning null.
- Use a built-in strategy to confirm the issue is in your custom code.
Example fix
// before
public SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {
return null; // invalid
}
// after
public SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {
return SampleSizeRounding.QUALITY;
} Defensive patterns
Strategy: validation
Validate before calling
// For a custom DownsampleStrategy, ensure getSampleSizeRounding never returns null.
@Override
public SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {
if (sw <= 0 || sh <= 0 || tw <= 0 || th <= 0) return SampleSizeRounding.QUALITY;
return /* real logic */ SampleSizeRounding.MEMORY;
} Prevention
- Always return a non-null SampleSizeRounding from custom strategies.
- Prefer delegating edge cases to DownsampleStrategy.DEFAULT.
- Add unit tests covering degenerate dimension inputs.
When it happens
Trigger: A custom DownsampleStrategy that returns null from getSampleSizeRounding. Built-in strategies return a non-null value, so this only occurs with user-supplied strategies or strategies invoked on degenerate (e.g. 0) dimensions.
Common situations: Registering an incomplete custom DownsampleStrategy that implements getScaleFactor but returns null from getSampleSizeRounding. Subclassing a strategy and forgetting to override getSampleSizeRounding when the parent returns null for some inputs.
Related errors
- Cannot scale with factor: {exactScaleFactor} from: {downsamp
- Cannot apply transformation on width: {outWidth} or height:
- Unable to convert {drawable} to a Bitmap
- Cannot obtain size for recycled Bitmap: {bitmap}[{width}x{he
- BufferedInputStream is closed
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/89c87cb1a3bdd58f.
Report an issue: GitHub.