{"record":{"id":"542147f283fdc52e","repo":"microg/GmsCore","slug":"field-not-found","errorCode":null,"errorMessage":"Field not found","messagePattern":"Field not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataType.java","lineNumber":170,"sourceCode":"        return fields;\n    }\n\n    /**\n     * Returns the namespaced name which uniquely identifies this data type.\n     */\n    @NonNull\n    public String getName() {\n        return name;\n    }\n\n    /**\n     * Returns the index of a field.\n     *\n     * @throws IllegalArgumentException If field isn't defined for this data type.\n     */\n    public int indexOf(@NonNull com.google.android.gms.fitness.data.Field field) {\n        int indexOf = this.fields.indexOf(field);\n        if (indexOf < 0) throw new IllegalArgumentException(\"Field not found\");\n        return indexOf;\n    }\n\n    /**\n     * Returns a list of output aggregate data types for the specified {@code inputDataType}.\n     * <p>\n     * To check if a data type is supported for aggregation, check that the returned list is not empty\n     * {@code DataType.getAggregatesForInput(dataType).isEmpty()}.\n     *\n     * @deprecated Use {@link #getAggregateType()} instead.\n     */\n    @NonNull\n    @Deprecated\n    public static List<DataType> getAggregatesForInput(@NonNull DataType inputDataType) {\n        DataType aggregateType = inputDataType.getAggregateType();\n        if (aggregateType == null) return Collections.emptyList();\n        return Collections.singletonList(aggregateType);\n    }","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataType.java#L152-L188","documentation":"Thrown by DataType.indexOf(Field) when the given Field is not one of the fields defined for this DataType. Each DataType has a fixed field list; indexOf resolves a Field to its positional index (used to read values from a DataPoint) and rejects unknown fields.","triggerScenarios":"Calling dataType.indexOf(field) with a Field object that does not belong to that DataType — e.g. Field.FIELD_CALORIES on DataType.TYPE_STEP_COUNT_DELTA, or a Field created from a different data type's definition.","commonSituations":"Hardcoding the wrong Field constant for a data type; iterating fields from one DataType while indexing into another; version drift where a Field exists in a newer play-services-fitness release but the data type in question never had it.","solutions":["Use the correct Field constant for that DataType (check the DataType's getFields() list).","Guard with dataType.getFields().contains(field) before calling indexOf.","Read values via dataPoint.getValue(field) instead of manual index math where possible.","Loop over dataType.getFields() rather than assuming field order/names."],"exampleFix":"// before\nint i = DataType.TYPE_STEP_COUNT_DELTA.indexOf(Field.FIELD_CALORIES); // throws\n// after\nField f = Field.FIELD_CALORIES;\nif (DataType.TYPE_STEP_COUNT_DELTA.getFields().contains(f)) {\n    int i = DataType.TYPE_STEP_COUNT_DELTA.indexOf(f);\n}","handlingStrategy":"validation","validationCode":"if (!dataType.getFields().contains(field)) throw new IllegalArgumentException(field.getName() + \" not valid for \" + dataType.getName());","typeGuard":"Optional<Integer> safeIndexOf(DataType dt, Field f) { int i = dt.getFields().indexOf(f); return i >= 0 ? Optional.of(i) : Optional.empty(); }","tryCatchPattern":"try { int i = dataType.indexOf(field); } catch (IllegalArgumentException e) { log.warn(\"Field {} not in {}\", field.getName(), dataType.getName()); }","preventionTips":["Look up the Field constant from the DataType's docs/getFields(), not memory.","Iterate dataType.getFields() rather than assuming field membership.","Avoid manual index math; use dataPoint.getValue(field).","Pin play-services-fitness versions and check Field availability per version."],"tags":["android","google-fit","field-not-found","validation"],"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"}