microg/GmsCore · error · IllegalArgumentException

Additional SessionProvider must not be null.

Error message

Additional SessionProvider must not be null.

What it means

CastContext.getSessionProviderMap builds the provider map from additional session providers and throws IllegalArgumentException when one of the supplied SessionProvider entries is null. It fires during CastContext initialization for apps that passed a null element in the additionalSessionProviders list.

Source

Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:162

        this.castSessionProvider = new CastSessionProvider(appContext, castOptions);
        try {
            this.delegate = CastDynamiteModule.newCastContext(appContext, castOptions, mediaRouter, getSessionProviderMap());
            this.sessionManager = new SessionManager(appContext, delegate.getSessionManagerImpl());
            this.discoveryManager = new DiscoveryManager(appContext, delegate.getDiscoveryManagerImpl());
        } catch (RemoteException e) {
            throw new IllegalStateException("Failed to call dynamite module", e);
        }
    }

    private Map<String, IBinder> getSessionProviderMap() {
        Map<String, IBinder> map = new HashMap<>();
        if (castSessionProvider != null) {
            map.put(castSessionProvider.getCategory(), castSessionProvider.asBinder());
        }
        List<SessionProvider> list = this.additionalSessionProviders;
        if (list != null) {
            for (SessionProvider sessionProvider : list) {
                if (sessionProvider == null) throw new IllegalArgumentException("Additional SessionProvider must not be null.");
                if (sessionProvider.getCategory() == null || sessionProvider.getCategory().isEmpty())
                    throw new IllegalArgumentException("Category for SessionProvider must not be null or empty string.");
                if (map.containsKey(sessionProvider.getCategory()))
                    throw new IllegalArgumentException("SessionProvider for category " + sessionProvider.getCategory() + " already added");
                map.put(sessionProvider.getCategory(), sessionProvider.asBinder());
            }
        }
        return map;
    }

    private static OptionsProvider getOptionsProvider(Context context) {
        try {
            Bundle metaData = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
            String optionsProviderClassName = metaData.getString(OPTIONS_PROVIDER_CLASS_NAME_KEY);
            if (optionsProviderClassName != null) {
                return Class.forName(optionsProviderClassName).asSubclass(OptionsProvider.class).getDeclaredConstructor().newInstance();
            }
            throw new IllegalStateException("The fully qualified name of the implementation of OptionsProvider must be provided as a metadata in the AndroidManifest.xml with key com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME.");

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Filter null entries out of additionalSessionProviders before constructing CastContext
  2. Fix the caller building the provider list so it never adds null
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at play-services-cast-framework/src/main/java/com/google/android/gms/cast/framework/CastContext.java:162 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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