{"record":{"id":"27c6b5c26f9ac61a","repo":"microg/GmsCore","slug":"expiration-not-set","errorCode":null,"errorMessage":"Expiration not set.","messagePattern":"Expiration not set\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/Geofence.java","lineNumber":118,"sourceCode":"        private int loiteringDelay = -1;\n        private int notificationResponsiveness;\n        private String requestId;\n        private @TransitionTypes int transitionTypes;\n\n        /**\n         * Creates a geofence object.\n         *\n         * @throws IllegalArgumentException if any parameters are not set or out of range\n         */\n        public Geofence build() throws IllegalArgumentException {\n            if (requestId == null) {\n                throw new IllegalArgumentException(\"Request ID not set.\");\n            } else if (transitionTypes == 0) {\n                throw new IllegalArgumentException(\"Transition types not set.\");\n            } else if ((transitionTypes & GEOFENCE_TRANSITION_DWELL) > 0 && loiteringDelay < 0) {\n                throw new IllegalArgumentException(\"Non-negative loitering delay needs to be set when transition types include GEOFENCE_TRANSITION_DWELLING.\");\n            } else if (expirationTime == Long.MIN_VALUE) {\n                throw new IllegalArgumentException(\"Expiration not set.\");\n            } else if (regionType == -1) {\n                throw new IllegalArgumentException(\"Geofence region not set.\");\n            } else if (notificationResponsiveness < 0) {\n                throw new IllegalArgumentException(\"Notification responsiveness should be nonnegative.\");\n            } else {\n                return new ParcelableGeofence(requestId, expirationTime, regionType, latitude, longitude, radius, transitionTypes, notificationResponsiveness, loiteringDelay);\n            }\n        }\n\n        /**\n         * Sets the region of this geofence. The geofence represents a circular area on a flat, horizontal plane.\n         *\n         * @param latitude  latitude in degrees, between -90 and +90 inclusive\n         * @param longitude longitude in degrees, between -180 and +180 inclusive\n         * @param radius    radius in meters\n         */\n        public Builder setCircularRegion(@FloatRange(from = -90.0d, to = 90.0d) double latitude, @FloatRange(from = -180.0d, to = 180.0d) double longitude, @FloatRange(from = 0.0d, fromInclusive = false) float radius) {\n            this.regionType = 1;","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/Geofence.java#L100-L136","documentation":"build() requires an expiration to be configured; expirationTime defaults to Long.MIN_VALUE meaning 'not set'. A geofence with no expiration would never be cleaned up, so the library rejects it with IllegalArgumentException.","triggerScenarios":"Calling build() without calling setExpirationDuration(long) or setExpirationTime(long) on the builder.","commonSituations":"Omitting expiration in minimal builder chains; confusion because some Google samples use NEVER_EXPIRATION (setExpirationDuration(NEVER_EXPIRE)) while this field must be explicitly set; copying pre-Builder ParcelableGeofence code.","solutions":["Call setExpirationDuration(millis) with a positive duration before build()","Use setExpirationDuration(Geofence.NEVER_EXPIRE) if the fence should persist until explicitly removed"],"exampleFix":"// before\nGeofence fence = new Geofence.Builder()\n    .setRequestId(\"fence1\")\n    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)\n    .setCircularRegion(lat, lng, radius)\n    .build(); // throws\n// after\nGeofence fence = new Geofence.Builder()\n    .setRequestId(\"fence1\")\n    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)\n    .setCircularRegion(lat, lng, radius)\n    .setExpirationDuration(60 * 60 * 1000L)\n    .build();","handlingStrategy":"validation","validationCode":"if (expirationDurationMillis <= 0 && expirationDurationMillis != Geofence.NEVER_EXPIRE) {\n    throw new IllegalStateException(\"Set a positive expiration duration\");\n}","typeGuard":null,"tryCatchPattern":"try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Expiration\")) { builder.setExpirationDuration(Geofence.NEVER_EXPIRE); return builder.build(); } throw e; }","preventionTips":["Always set setExpirationDuration() — use Geofence.NEVER_EXPIRE for persistent fences","Centralize geofence creation in one helper with sensible defaults"],"tags":["geofencing","validation","android","expiration"],"backgroundTag":"missing-required-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"}