{"record":{"id":"5e9e62d71d38c7f4","repo":"microg/GmsCore","slug":"attempting-to-read-data-for-session-which-was-not","errorCode":null,"errorMessage":"Attempting to read data for session which was not returned","messagePattern":"Attempting to read data for session which was not returned","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-fitness/src/main/java/com/google/android/gms/fitness/result/SessionReadResult.java","lineNumber":79,"sourceCode":"    @Hide\n    public SessionReadResult(@Param(1) @NonNull List<Session> sessions, @Param(2) @NonNull List<SessionDataSet> sessionDataSets, @Param(3) @NonNull Status status) {\n        this.sessions = sessions;\n        this.sessionDataSets = sessionDataSets;\n        this.status = status;\n    }\n\n    /**\n     * Returns the data sets for a given {@code session} and {@code dataType}. If a specific data source was requested for this data type in the read request, the\n     * returned data set is from that source. Else, the default data source for this data type is used. Returns empty if no data for the requested data\n     * type is found.\n     *\n     * @return Data sets for the given session and data type, empty if no data was found. Multiple data sets may be returned for a given type, based\n     * on the read request\n     * @throws IllegalArgumentException If the given session was not part of getSessions() output.\n     */\n    @NonNull\n    public List<DataSet> getDataSet(@NonNull Session session, @NonNull DataType dataType) {\n        if (!sessions.contains(session)) throw new IllegalArgumentException(\"Attempting to read data for session which was not returned\");\n        List<DataSet> dataSets = new ArrayList<>();\n        for (SessionDataSet sessionDataSet : this.sessionDataSets) {\n            if (session.equals(sessionDataSet.session) && dataType.equals(sessionDataSet.dataSet.getDataType())) {\n                dataSets.add(sessionDataSet.dataSet);\n            }\n        }\n        return dataSets;\n    }\n\n    /**\n     * Returns the data sets for all data sources for a given {@code session}. If a specific data source was requested for a data type in the read request,\n     * the returned data set is from that source. Else, the default data source for the requested data type is used.\n     *\n     * @return Data sets for the given session for all data sources, empty if no data was found. Multiple data sets may be returned for a given type,\n     * based on the read request\n     * @throws IllegalArgumentException If the given session was not part of getSessions() output\n     */\n    @NonNull","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-fitness/src/main/java/com/google/android/gms/fitness/result/SessionReadResult.java#L61-L97","documentation":"SessionReadResult.getDataSet(Session, DataType) throws IllegalArgumentException when the given Session was not part of the result's getSessions() output. The result can only serve data for sessions it actually returned from the read request.","triggerScenarios":"Calling result.getDataSet(session, dataType) with a Session object that came from a different query, was constructed locally, or was filtered out of the SessionReadResult.","commonSituations":"Cross-referencing sessions from SessionsApi history with a SessionReadResult from a different read call; caching Session objects across queries; expecting data for sessions excluded by the read request's time window.","solutions":["Only call getDataSet with sessions obtained from the same SessionReadResult's getSessions().","Check result.getSessions().contains(session) before calling getDataSet.","Re-issue the session read request covering the time range of the session you need."],"exampleFix":"// before\nList<DataSet> data = result.getDataSet(mySession, DataType.TYPE_STEP_COUNT_DELTA); // may throw\n\n// after\nif (result.getSessions().contains(mySession)) {\n    List<DataSet> data = result.getDataSet(mySession, DataType.TYPE_STEP_COUNT_DELTA);\n}","handlingStrategy":"validation","validationCode":"if (!result.getSessions().contains(session)) {\n    return Collections.emptyList();\n}","typeGuard":null,"tryCatchPattern":"try {\n    return result.getDataSet(session, dataType);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Session not in read result\");\n    return Collections.emptyList();\n}","preventionTips":["Only pass Session objects from result.getSessions()","Do not cache Session objects across queries","Ensure the read request window covers the session"],"tags":["google-fit","android","illegal-argument","session"],"backgroundTag":"invalid-argument-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"}