microg/GmsCore · error · IllegalArgumentException

Category for SessionProvider must not be null or empty strin

Error message

Category for SessionProvider must not be null or empty string.

What it means

Validation in CastContext.getSessionProviderMap: a SessionProvider's getCategory() returned null or an empty string, so it cannot be used as a map key. The provider with the unusable category is the input at fault.

Source

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

            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.");
        } catch (PackageManager.NameNotFoundException | ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException |
                 InvocationTargetException | NullPointerException e) {

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Override SessionProvider.getCategory() to return a non-empty unique category string
  2. Drop providers whose category is unusable before constructing CastContext
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:164 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/f96c66ce43e52d4c. Report an issue: GitHub.