microg/GmsCore · error · IllegalStateException

dataType must be set

Error message

dataType must be set

What it means

Thrown by DataSource.Builder.build() when no DataType has been set. A DataSource must declare what kind of data it produces (e.g. TYPE_STEP_COUNT_DELTA); without a DataType the resulting DataSource would be invalid, so the builder refuses to construct it.

Solutions

  1. Call setDataType(DataType.AGGREGATE_...) or the appropriate DataType before build().
  2. If the data type is dynamic, assert/validate it is non-null before building.
  3. Wrap the dataType in an Optional and throw a clear app-level error early if missing.
  4. Check that you are building the intended Builder instance (not a fresh one that lost the setDataType call).

Example fix

// before
DataSource src = new DataSource.Builder()
    .setType(DataSource.TYPE_RAW)
    .build(); // throws
// after
DataSource src = new DataSource.Builder()
    .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
    .setType(DataSource.TYPE_RAW)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (builderDataType == null) throw new IllegalStateException("setDataType must be called before build()");

Type guard

boolean sourceReady(DataSource.Builder b, DataType dt) { return dt != null; }

Try / catch

try { src = dataSourceBuilder.build(); } catch (IllegalStateException e) { throw new ConfigException("DataSource missing dataType", e); }

Prevention

When it happens

Trigger: Calling DataSource.Builder.build() without ever calling setDataType(DataType) on that builder.

Common situations: Copy-pasted builder code where the setDataType line was deleted; conditional config where the data type comes from a null variable; refactors that split builder construction across methods and skip the dataType step.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/f9cd1ccecb551093. Report an issue: GitHub.

Appendix: source

Thrown at play-services-fitness/src/main/java/com/google/android/gms/fitness/data/DataSource.java:199

    /**
     * A builder that can be used to construct new data source objects. In general, a built data source should be saved in memory to avoid the cost
     * of re-constructing it for every request.
     */
    public static class Builder {
        private DataType dataType;
        private Device device;
        private Application application;
        private int type = -1;
        private String streamName = "";

        /**
         * Finishes building the data source and returns a DataSource object.
         *
         * @throws IllegalStateException If the builder didn't have enough data to build a valid data source.
         */
        @NonNull
        public DataSource build() {
            if (dataType == null) throw new IllegalStateException("dataType must be set");
            if (type < 0) throw new IllegalStateException("type must be set");
            return new DataSource(dataType, type, device, application, streamName);
        }

        /**
         * Sets the package name for the application that is recording or computing the data. Used for data sources that aren't built into the platform
         * (local sensors and BLE sensors are built-in). It can be used to identify the data source, to disambiguate between data from different
         * applications, and also to link back to the original application for a detailed view.
         */
        @NonNull
        public Builder setAppPackageName(@NonNull String packageName) {
            Application application = Application.GMS_APP;
            this.application = Constants.GMS_PACKAGE_NAME.equals(packageName) ? Application.GMS_APP : new Application(packageName);
            return this;
        }

        /**
         * Sets the package name for the application that is recording or computing the data based on the app's context. This method should be

View on GitHub (pinned to 157c9d86ac)