microg/GmsCore · error · IllegalArgumentException
Attempting to read data for session which was not returned
Error message
Attempting to read data for session which was not returned
What it means
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.
Source
Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/result/SessionReadResult.java:79
@Hide
public SessionReadResult(@Param(1) @NonNull List<Session> sessions, @Param(2) @NonNull List<SessionDataSet> sessionDataSets, @Param(3) @NonNull Status status) {
this.sessions = sessions;
this.sessionDataSets = sessionDataSets;
this.status = status;
}
/**
* 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
* 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
* type is found.
*
* @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
* on the read request
* @throws IllegalArgumentException If the given session was not part of getSessions() output.
*/
@NonNull
public List<DataSet> getDataSet(@NonNull Session session, @NonNull DataType dataType) {
if (!sessions.contains(session)) throw new IllegalArgumentException("Attempting to read data for session which was not returned");
List<DataSet> dataSets = new ArrayList<>();
for (SessionDataSet sessionDataSet : this.sessionDataSets) {
if (session.equals(sessionDataSet.session) && dataType.equals(sessionDataSet.dataSet.getDataType())) {
dataSets.add(sessionDataSet.dataSet);
}
}
return dataSets;
}
/**
* 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,
* the returned data set is from that source. Else, the default data source for the requested data type is used.
*
* @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,
* based on the read request
* @throws IllegalArgumentException If the given session was not part of getSessions() output
*/
@NonNullView on GitHub (pinned to 157c9d86ac)
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.
Example fix
// before
List<DataSet> data = result.getDataSet(mySession, DataType.TYPE_STEP_COUNT_DELTA); // may throw
// after
if (result.getSessions().contains(mySession)) {
List<DataSet> data = result.getDataSet(mySession, DataType.TYPE_STEP_COUNT_DELTA);
} Defensive patterns
Strategy: validation
Validate before calling
if (!result.getSessions().contains(session)) {
return Collections.emptyList();
} Try / catch
try {
return result.getDataSet(session, dataType);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Session not in read result");
return Collections.emptyList();
} Prevention
- Only pass Session objects from result.getSessions()
- Do not cache Session objects across queries
- Ensure the read request window covers the session
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- deleteAll was set to true but keys were also provided
- Element in keys cannot be null or empty
- retrieveAll was set to true but other constraint(s) was also
- Element in keys cannot be null or empty
- Required account information missing
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/5e9e62d71d38c7f4.
Report an issue: GitHub.