{"record":{"id":"89c87cb1a3bdd58f","repo":"bumptech/glide","slug":"cannot-round-with-null-rounding","errorCode":null,"errorMessage":"Cannot round with null rounding","messagePattern":"Cannot round with null rounding","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java","lineNumber":570,"sourceCode":"              + \" from: \"\n              + downsampleStrategy\n              + \", source: [\"\n              + sourceWidth\n              + \"x\"\n              + sourceHeight\n              + \"]\"\n              + \", target: [\"\n              + targetWidth\n              + \"x\"\n              + targetHeight\n              + \"]\");\n    }\n\n    SampleSizeRounding rounding =\n        downsampleStrategy.getSampleSizeRounding(\n            orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight);\n    if (rounding == null) {\n      throw new IllegalArgumentException(\"Cannot round with null rounding\");\n    }\n\n    int outWidth = round(exactScaleFactor * orientedSourceWidth);\n    int outHeight = round(exactScaleFactor * orientedSourceHeight);\n\n    int widthScaleFactor = orientedSourceWidth / outWidth;\n    int heightScaleFactor = orientedSourceHeight / outHeight;\n\n    // TODO: This isn't really right for both CenterOutside and CenterInside. Consider allowing\n    // DownsampleStrategy to pick, or trying to do something more sophisticated like picking the\n    // scale factor that leads to an exact match.\n    int scaleFactor =\n        rounding == SampleSizeRounding.MEMORY\n            ? Math.max(widthScaleFactor, heightScaleFactor)\n            : Math.min(widthScaleFactor, heightScaleFactor);\n\n    int powerOfTwoSampleSize;\n    // BitmapFactory does not support downsampling wbmp files on platforms <= M. See b/27305903.","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java#L552-L588","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {\n  return null; // invalid\n}\n// after\npublic SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {\n  return SampleSizeRounding.QUALITY;\n}","handlingStrategy":"validation","validationCode":"// For a custom DownsampleStrategy, ensure getSampleSizeRounding never returns null.\n@Override\npublic SampleSizeRounding getSampleSizeRounding(int sw, int sh, int tw, int th) {\n  if (sw <= 0 || sh <= 0 || tw <= 0 || th <= 0) return SampleSizeRounding.QUALITY;\n  return /* real logic */ SampleSizeRounding.MEMORY;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always return a non-null SampleSizeRounding from custom strategies.","Prefer delegating edge cases to DownsampleStrategy.DEFAULT.","Add unit tests covering degenerate dimension inputs."],"tags":["downsample","decode","strategy","bitmap","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}