{"record":{"id":"edff5c0d75815aac","repo":"microg/GmsCore","slug":"height-must-not-be-negative","errorCode":null,"errorMessage":"height must not be negative","messagePattern":"height must not be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java","lineNumber":262,"sourceCode":"     * dimensions specified (i.e., its proportions will not necessarily be preserved).\n     *\n     * @param location the location on the map {@code LatLng} to which the anchor point in the\n     *                 given image will remain fixed. The anchor will remain fixed to the position\n     *                 on the ground when transformations are applied (e.g., setDimensions,\n     *                 setBearing, etc.).\n     * @param width    the width of the overlay (in meters)\n     * @param height   the height of the overlay (in meters)\n     * @return this {@link GroundOverlayOptions} object with a new position set.\n     * @throws IllegalArgumentException if anchor is null\n     * @throws IllegalArgumentException if width or height are negative\n     * @throws IllegalStateException    if the position was already set using\n     *                                  {@link #positionFromBounds(LatLngBounds)}\n     */\n    public GroundOverlayOptions position(LatLng location, float width, float height)\n            throws IllegalArgumentException, IllegalStateException {\n        position(location, width);\n        if (height < 0)\n            throw new IllegalArgumentException(\"height must not be negative\");\n        this.height = height;\n        return this;\n    }\n\n    /**\n     * Specifies the position for this ground overlay using an anchor point (a {@link LatLng}) and\n     * the width (in meters). When rendered, the image will retain its proportions from the bitmap,\n     * i.e., the height will be calculated to preserve the original proportions of the image.\n     *\n     * @param location the location on the map {@link LatLng} to which the anchor point in the\n     *                 given image will remain fixed. The anchor will remain fixed to the position\n     *                 on the ground when transformations are applied (e.g., setDimensions,\n     *                 setBearing, etc.).\n     * @param width    the width of the overlay (in meters). The height will be determined\n     *                 automatically based on the image proportions.\n     * @return this {@link GroundOverlayOptions} object with a new position set.\n     * @throws IllegalArgumentException if anchor is null\n     * @throws IllegalArgumentException if width is negative","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java#L244-L280","documentation":"GroundOverlayOptions.position(LatLng, float width, float height) throws IllegalArgumentException when the height argument is negative. The overlay is sized explicitly from width and height in meters, so negative dimensions have no geometric meaning. Note this overload first delegates to position(location, width), so width and null-location checks run before the height check.","triggerScenarios":"Calling groundOverlayOptions.position(latLng, width, height) with height < 0, typically from a computed dimension (e.g. scaling an image's meter size by a negative factor) or swapped/mistyped arguments.","commonSituations":"Deriving overlay size from image aspect ratio and a scale factor that can be negative after a sign error; unit-conversion mistakes (feet vs meters is fine, but a negated delta is not); copy-paste where width and height variables are swapped in a call.","solutions":["Validate/clamp height to a non-negative value before calling position(): if (height < 0) height = 0; or fix the computation.","Verify the arguments are in the right order — position(LatLng, width, height) — and that the size calculation cannot go negative.","If only width matters, use the two-argument overload position(LatLng, float) so height is derived from the image."],"exampleFix":"// before\nfloat height = imgHeightMeters * scale; // scale may be negative\nmap.addGroundOverlay(options.position(center, width, height));\n\n// after\nfloat height = Math.max(0f, imgHeightMeters * scale);\nmap.addGroundOverlay(options.position(center, width, height));","handlingStrategy":"validation","validationCode":"if (height < 0f) throw new IllegalArgumentException(\"caller bug: negative height \" + height); // or clamp","typeGuard":"boolean validSize(float w, float h) { return w >= 0f && h >= 0f; }","tryCatchPattern":"try {\n    options.position(center, width, height);\n} catch (IllegalArgumentException e) {\n    options.position(center, width, Math.max(0f, height));\n}","preventionTips":["Clamp computed dimensions to >= 0 before configuring overlays.","Double-check argument order (LatLng, width, height).","Validate any user/config-supplied sizes at load time."],"tags":["maps","android","ground-overlay","range-check"],"backgroundTag":"argument-out-of-range","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}