{"record":{"id":"f247bfbbd565d929","repo":"microg/GmsCore","slug":"priority-priority-must-be-a-priority-priority","errorCode":null,"errorMessage":"priority {priority} must be a Priority.PRIORITY_* constant","messagePattern":"priority (.+?) must be a Priority\\.PRIORITY_\\* constant","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/org/microg/gms/location/PriorityUtil.java","lineNumber":26,"sourceCode":"import androidx.annotation.NonNull;\nimport com.google.android.gms.location.Priority;\n\npublic class PriorityUtil {\n    public static boolean isValidPriority(@Priority int priority) {\n        switch (priority) {\n            default:\n                return false;\n            case Priority.PRIORITY_HIGH_ACCURACY:\n            case Priority.PRIORITY_BALANCED_POWER_ACCURACY:\n            case Priority.PRIORITY_LOW_POWER:\n            case Priority.PRIORITY_PASSIVE:\n                return true;\n        }\n    }\n\n    public static int checkValidPriority(@Priority int priority) {\n        if (!isValidPriority(priority)) {\n            throw new IllegalArgumentException(\"priority \" + priority + \" must be a Priority.PRIORITY_* constant\");\n        }\n        return priority;\n    }\n\n    @NonNull\n    public static String priorityToString(@Priority int priority) {\n        switch (priority) {\n            case Priority.PRIORITY_HIGH_ACCURACY:\n                return \"HIGH_ACCURACY\";\n            case Priority.PRIORITY_BALANCED_POWER_ACCURACY:\n                return \"BALANCED_POWER_ACCURACY\";\n            case Priority.PRIORITY_LOW_POWER:\n                return \"LOW_POWER\";\n            case Priority.PRIORITY_PASSIVE:\n                return \"PASSIVE\";\n            default:\n                throw new IllegalArgumentException();\n        }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/org/microg/gms/location/PriorityUtil.java#L8-L44","documentation":"PriorityUtil.checkValidPriority validates that the given @Priority int is one of the Priority.PRIORITY_* constants defined by the library (isValidPriority). Any integer outside the allowed set throws IllegalArgumentException, since location requests require a well-defined priority.","triggerScenarios":"Passing an invalid priority to checkValidPriority or to a LocationRequest builder that validates it — e.g. 0, 100, a bitfield, or a constant from a different enum (granularity/throttle behavior) mistakenly used as a priority.","commonSituations":"Hard-coded numeric priorities copied from old com.google.android.gms.location.LocationRequest (e.g. PRIORITY_HIGH_ACCURACY as 100) mixed with new constants; using Camera or other library constants; JSON/config-driven values not whitelisted.","solutions":["Use only Priority.PRIORITY_* constants (e.g. PRIORITY_HIGH_ACCURACY, PRIORITY_BALANCED_POWER_ACCURACY, PRIORITY_LOW_POWER, PRIORITY_PASSIVE)","Do not combine priority constants with bitwise OR","Validate user/config supplied values against isValidPriority before constructing requests"],"exampleFix":"// before\nLocationRequest request = new LocationRequest.Builder(0) // invalid priority\n    .build();\n// after\nLocationRequest request = new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY)\n    .build();","handlingStrategy":"validation","validationCode":"static boolean isKnownPriority(int p) {\n    return p == Priority.PRIORITY_HIGH_ACCURACY\n        || p == Priority.PRIORITY_BALANCED_POWER_ACCURACY\n        || p == Priority.PRIORITY_LOW_POWER\n        || p == Priority.PRIORITY_PASSIVE;\n}","typeGuard":null,"tryCatchPattern":"try { PriorityUtil.checkValidPriority(p); } catch (IllegalArgumentException e) { p = Priority.PRIORITY_BALANCED_POWER_ACCURACY; }","preventionTips":["Use Priority.PRIORITY_* constants only","Do not reuse constants from other enums (granularity, throttle) as priorities","Sanitize user/config-driven priority values"],"tags":["android","location","validation","enum"],"backgroundTag":"invalid-enum-value","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"}