{"record":{"id":"952b6278f53cb479","repo":"didi/DoKit","slug":"center-crop-and-center-inside-can-not-be-used-toge","errorCode":null,"errorMessage":"Center crop and center inside can not be used together.","messagePattern":"Center crop and center inside can not be used together\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":457,"sourceCode":"    /**\n     * Add a list of custom transformations to be applied to the image.\n     * <p>\n     * Custom transformations will always be run after the built-in transformations.\n     */\n    public Builder transform(List<? extends Transformation> transformations) {\n      if (transformations == null) {\n        throw new IllegalArgumentException(\"Transformation list must not be null.\");\n      }\n      for (int i = 0, size = transformations.size(); i < size; i++) {\n        transform(transformations.get(i));\n      }\n      return this;\n    }\n\n    /** Create the immutable {@link Request} object. */\n    public Request build() {\n      if (centerInside && centerCrop) {\n        throw new IllegalStateException(\"Center crop and center inside can not be used together.\");\n      }\n      if (centerCrop && (targetWidth == 0 && targetHeight == 0)) {\n        throw new IllegalStateException(\n            \"Center crop requires calling resize with positive width and height.\");\n      }\n      if (centerInside && (targetWidth == 0 && targetHeight == 0)) {\n        throw new IllegalStateException(\n            \"Center inside requires calling resize with positive width and height.\");\n      }\n      if (priority == null) {\n        priority = Priority.NORMAL;\n      }\n      return new Request(uri, resourceId, stableKey, transformations, targetWidth, targetHeight,\n          centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, rotationPivotY,\n          hasRotationPivot, config, priority);\n    }\n  }\n}","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L439-L475","documentation":"Thrown by Request.Builder.build() as a defensive invariant check when both centerCrop and centerInside flags are true. The public setters already block setting both (see errors 123/124), so this normally indicates the builder state was manipulated directly (reflection, subclassing, or a modified vendored copy such as this DoKit fork).","triggerScenarios":"Setting both flags true through reflection or a custom Builder subclass, or a locally modified copy of Picasso where a setter guard was removed; then calling build().","commonSituations":"Forking/vendoring Picasso (as DoKit does) and relaxing one of the setter guards without realizing build() re-checks the invariant; bytecode manipulation or test code that sets fields directly.","solutions":["Use only one of centerCrop()/centerInside(); the two scaling behaviors are mutually exclusive by design.","If you modified the vendored setters, also decide the combined behavior explicitly instead of relying on build() not to notice.","Set builder fields only through the public fluent API."],"exampleFix":"// before (reflection / direct field manipulation)\nField f = builder.getClass().getDeclaredField(\"centerCrop\"); // ...both flags forced true\n\n// after\nbuilder.resize(200, 200).centerCrop(); // one strategy, set via the public API","handlingStrategy":"validation","validationCode":"// Guard in your wrapper before build()\nif (usingCrop && usingInside) throw new IllegalArgumentException(\"pick one strategy\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set builder flags via reflection or field access.","If you fork Picasso (as DoKit did), keep setter guards and the build() invariant consistent."],"tags":["android","picasso","builder","invariant","defensive-check"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}