{"record":{"id":"2e0ef0f1bff0f0dd","repo":"microg/GmsCore","slug":"unsupportedoperationexception","errorCode":null,"errorMessage":"UnsupportedOperationException","messagePattern":"UnsupportedOperationException","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"play-services-location/src/main/java/com/google/android/gms/location/SleepClassifyEvent.java","lineNumber":33,"sourceCode":"import java.util.List;\n\n/**\n * Represents a sleep classification event including the classification timestamp, the sleep confidence, and the\n * supporting data such as device motion and ambient light level. Classification events are reported at a regular\n * intervals, such as every 10 minutes.\n */\npublic class SleepClassifyEvent extends AutoSafeParcelable {\n    public static final Creator<SleepClassifyEvent> CREATOR = new AutoCreator<>(SleepClassifyEvent.class);\n\n    /**\n     * Extracts the {@code SleepClassifyEvent} from an {@code Intent}.\n     *\n     * @param intent the {@code Intent} to extract from\n     * @return a list of {@link SleepClassifyEvent}s if the intent has events, or an empty list if the intent doesn't\n     * contain any events.\n     */\n    public static List<SleepClassifyEvent> extractEvents(Intent intent) {\n        throw new UnsupportedOperationException();\n    }\n\n    /**\n     * Returns a sleep confidence value between 0 and 100. Higher values indicate that the user is more likely sleeping,\n     * while lower values indicate that the user is more likely awake.\n     */\n    public int getConfidence() {\n        throw new UnsupportedOperationException();\n    }\n\n    /**\n     * Returns the brightness of the space around the device, based on the device's ambient light sensor readings. Value\n     * ranges from 1 to 6, inclusive. Higher values indicate brighter surroundings, while lower values indicate darker\n     * surroundings.\n     */\n    public int getLight() {\n        throw new UnsupportedOperationException();\n    }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/src/main/java/com/google/android/gms/location/SleepClassifyEvent.java#L15-L51","documentation":"SleepClassifyEvent.extractEvents(Intent) is a stub in this pure-Java/play-services-artifacts source: it unconditionally throws UnsupportedOperationException. The real implementation only exists inside Google Play services on a device; the class bundled with the client library contains no logic.","triggerScenarios":"Calling SleepClassifyEvent.extractEvents(intent) with any Intent, in any environment, since the method body is only 'throw new UnsupportedOperationException()'.","commonSituations":"Calling the method in unit tests or on an emulator, or linking against a client-library artifact where the runtime Google Play services portion is absent (or the code path runs before Play services delivers the actual implementation).","solutions":["Don't call this stub directly; rely on the runtime Play services implementation on a real device with Google Play services available.","Guard the call behind a GoogleApiAvailability check and fall back gracefully.","In unit tests, avoid invoking it or mock the static method.","Check that the app is using the correct play-services-location dependency and that activity-recognition/sleep APIs are actually available on the target device."],"exampleFix":"// before\nList<SleepClassifyEvent> events = SleepClassifyEvent.extractEvents(intent);\n// after\nif (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {\n    List<SleepClassifyEvent> events = SleepClassifyEvent.extractEvents(intent);\n} else {\n    List<SleepClassifyEvent> events = Collections.emptyList(); // fallback\n}","handlingStrategy":"try-catch","validationCode":"boolean available = GoogleApiAvailability.getInstance()\n    .isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS;\nif (!available) return Collections.emptyList();","typeGuard":null,"tryCatchPattern":"try {\n    return SleepClassifyEvent.extractEvents(intent);\n} catch (UnsupportedOperationException e) {\n    return Collections.emptyList();\n}","preventionTips":["Only call sleep APIs on devices with Google Play services","Avoid calling SleepClassifyEvent methods in plain JVM unit tests","Check GoogleApiAvailability before using activity/sleep APIs"],"tags":["android","play-services","stub","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}