{"record":{"id":"bdebdb139e0aacc3","repo":"microg/GmsCore","slug":"location-must-not-be-null","errorCode":null,"errorMessage":"location must not be null","messagePattern":"location must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java","lineNumber":287,"sourceCode":"     * 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\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)}","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java#L269-L305","documentation":"GroundOverlayOptions.position(LatLng, float width) throws IllegalArgumentException when the location argument is null. A ground overlay must be anchored at a real LatLng, so the library rejects a null anchor eagerly. This is the shared position path also used by the three-argument overload, so it is checked first there.","triggerScenarios":"Calling position(null, width) (or the width+height overload with a null LatLng), or passing a nullable LatLng resolved from geocoding, a saved bundle, or a marker lookup that returned null.","commonSituations":"Geocoder or places-API result is null (no match for the address string); restoring overlay state from a Bundle where the LatLng key is missing; computing a position from a Nullable location before the first fix.","solutions":["Null-check the LatLng before calling position() and skip adding the overlay or fall back to a known default location.","Handle null geocoding/results upstream and resolve to a concrete coordinate before configuring the overlay.","Guard bundle restoration: if (bundle.containsKey(KEY)) { LatLng loc = bundle.getParcelable(KEY); if (loc != null) ... }"],"exampleFix":"// before\nLatLng center = geocode(address); // may be null\nmap.addGroundOverlay(new GroundOverlayOptions().position(center, 1000f));\n\n// after\nLatLng center = geocode(address);\nif (center != null) {\n    map.addGroundOverlay(new GroundOverlayOptions().position(center, 1000f));\n}","handlingStrategy":"type-guard","validationCode":"if (location == null) { return; /* skip overlay or use default */ }","typeGuard":"boolean canPlaceOverlay(LatLng loc) { return loc != null; }","tryCatchPattern":"try {\n    options.position(location, width);\n} catch (IllegalArgumentException e) {\n    // resolve location or skip overlay creation\n}","preventionTips":["Null-check geocoding/lookup results before using them as anchors.","Handle missing Bundle keys when restoring overlay state.","Skip overlay creation entirely when no valid coordinate exists."],"tags":["maps","android","ground-overlay","null-check"],"backgroundTag":"null-argument","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"}