{"record":{"id":"564549bbd8ebb297","repo":"microg/GmsCore","slug":"width-must-not-be-negative","errorCode":null,"errorMessage":"width must not be negative","messagePattern":"width 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":289,"sourceCode":"     *\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\n     * @throws IllegalStateException    if the position was already set using\n     *                                  {@link #positionFromBounds(LatLngBounds)}\n     */\n    public GroundOverlayOptions position(LatLng location, float width)\n            throws IllegalArgumentException, IllegalStateException {\n        if (location == null)\n            throw new IllegalArgumentException(\"location must not be null\");\n        if (width < 0)\n            throw new IllegalArgumentException(\"width must not be negative\");\n        if (bounds != null)\n            throw new IllegalStateException(\"Position already set using positionFromBounds()\");\n        this.location = location;\n        this.width = width;\n        return this;\n    }\n\n    /**\n     * Specifies the position for this ground overlay. When rendered, the image will be scaled to\n     * fit the bounds (i.e., its proportions will not necessarily be preserved).\n     *\n     * @param bounds a {@link LatLngBounds} in which to place the ground overlay\n     * @return this {@link GroundOverlayOptions} object with a new position set.\n     * @throws IllegalStateException if the position was already set using\n     *                               {@link #position(LatLng, float)} or\n     *                               {@link #position(LatLng, float, float)}\n     */\n    public GroundOverlayOptions positionFromBounds(LatLngBounds bounds)","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java#L271-L307","documentation":"GroundOverlayOptions.position(LatLng, float width) throws IllegalArgumentException when the width argument is negative. Width (in meters) defines the overlay's ground footprint; a negative value is meaningless and rejected. This check runs after the null-location check and before the positionFromBounds conflict check.","triggerScenarios":"Calling position(latLng, width) with width < 0, e.g. a computed meter width from a scale factor that went negative, an argument-order mix-up, or an unvalidated user-entered size.","commonSituations":"Overlay sizes derived from zoom-dependent scaling calculations that can invert sign; mistakes converting between units; feeding untrusted configuration values directly into the options builder.","solutions":["Clamp width before the call: width = Math.max(0f, computedWidth);","Fix the size computation so it cannot produce negative values, or validate configuration inputs at load time.","Consider positionFromBounds(LatLngBounds) if the overlay should derive its size from geography instead of an explicit width."],"exampleFix":"// before\nfloat width = baseWidth * zoomScale; // may be negative\noptions.position(center, width);\n\n// after\nfloat width = Math.max(0f, baseWidth * zoomScale);\noptions.position(center, width);","handlingStrategy":"validation","validationCode":"if (width < 0f) width = 0f; // or fix the computation","typeGuard":"boolean validWidth(float w) { return w >= 0f; }","tryCatchPattern":"try {\n    options.position(center, width);\n} catch (IllegalArgumentException e) {\n    options.position(center, Math.max(0f, width));\n}","preventionTips":["Clamp scaled/computed widths to non-negative values.","Validate untrusted configuration values before passing them in.","Consider positionFromBounds() when size should come from geography."],"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-14T00:17:10.932Z"}