{"record":{"id":"b0925e6f87735254","repo":"microg/GmsCore","slug":"throttle-behavior-throttlebehavior-must-be-a-thr","errorCode":null,"errorMessage":"throttle behavior {throttleBehavior} must be a ThrottleBehavior.THROTTLE_* constant","messagePattern":"throttle behavior (.+?) must be a ThrottleBehavior\\.THROTTLE_\\* constant","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/org/microg/gms/location/ThrottleBehaviorUtil.java","lineNumber":25,"sourceCode":"\nimport androidx.annotation.NonNull;\nimport com.google.android.gms.location.ThrottleBehavior;\n\npublic class ThrottleBehaviorUtil {\n    public static boolean isValidThrottleBehavior(@ThrottleBehavior int throttleBehavior) {\n        switch (throttleBehavior) {\n            default:\n                return false;\n            case ThrottleBehavior.THROTTLE_BACKGROUND:\n            case ThrottleBehavior.THROTTLE_ALWAYS:\n            case ThrottleBehavior.THROTTLE_NEVER:\n                return true;\n        }\n    }\n\n    public static int checkValidThrottleBehavior(@ThrottleBehavior int throttleBehavior) {\n        if (!isValidThrottleBehavior(throttleBehavior)) {\n            throw new IllegalArgumentException(\"throttle behavior \" + throttleBehavior + \" must be a ThrottleBehavior.THROTTLE_* constant\");\n        }\n        return throttleBehavior;\n    }\n\n    @NonNull\n    public static String throttleBehaviorToString(@ThrottleBehavior int throttleBehavior) {\n        switch (throttleBehavior) {\n            case ThrottleBehavior.THROTTLE_BACKGROUND:\n                return \"THROTTLE_BACKGROUND\";\n            case ThrottleBehavior.THROTTLE_ALWAYS:\n                return \"THROTTLE_ALWAYS\";\n            case ThrottleBehavior.THROTTLE_NEVER:\n                return \"THROTTLE_NEVER\";\n            default:\n                throw new IllegalArgumentException();\n        }\n    }\n}","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/org/microg/gms/location/ThrottleBehaviorUtil.java#L7-L43","documentation":"ThrottleBehaviorUtil.checkValidThrottleBehavior validates that the given int is one of the ThrottleBehavior.THROTTLE_* constants (isValidThrottleBehavior). Any other integer throws IllegalArgumentException, because throttle behavior must be a well-defined enum value for the location request.","triggerScenarios":"Passing an arbitrary int (0, 3, combined bitfield, or a constant from another enum) where a ThrottleBehavior value is expected, e.g. in LocationRequest building code that validates via checkValidThrottleBehavior.","commonSituations":"Config/remote-config supplied throttle values not whitelisted; confusing Priority or Granularity constants with ThrottleBehavior; hard-coded numbers instead of ThrottleBehavior.THROTTLE_* references.","solutions":["Use only the defined ThrottleBehavior.THROTTLE_* constants","Never bitwise-combine throttle behavior constants","Validate externally supplied ints with isValidThrottleBehavior before use"],"exampleFix":"// before\nint behavior = 0; // not a THROTTLE_* constant\ncheckValidThrottleBehavior(behavior);\n// after\nint behavior = ThrottleBehavior.THROTTLE_ALWAYS_ON;\ncheckValidThrottleBehavior(behavior);","handlingStrategy":"validation","validationCode":"// whitelist ThrottleBehavior.THROTTLE_* constants before calling\nif (behavior != ThrottleBehavior.THROTTLE_ALWAYS_ON\n    && behavior != ThrottleBehavior.THROTTLE_BACKGROUND_RESTRICTED\n    && behavior != ThrottleBehavior.THROTTLE_NEVER) {\n    behavior = ThrottleBehavior.THROTTLE_ALWAYS_ON;\n}","typeGuard":null,"tryCatchPattern":"try { ThrottleBehaviorUtil.checkValidThrottleBehavior(b); } catch (IllegalArgumentException e) { b = ThrottleBehavior.THROTTLE_ALWAYS_ON; }","preventionTips":["Reference ThrottleBehavior.THROTTLE_* constants, never raw ints","Do not mix Priority/Granularity values into throttle fields","Validate remote-config values before applying"],"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"}