microg/GmsCore · error · IllegalArgumentException
tag invalid
Error message
tag invalid
What it means
GcmNetworkManager.cancelTask throws IllegalArgumentException when the tag is empty or (per this implementation) when its length is not < 100 characters. Tags must be non-empty, unique per endpoint, and under the length limit to be addressable by the scheduler.
Source
Thrown at play-services-gcm/src/main/java/com/google/android/gms/gcm/GcmNetworkManager.java:165
public void cancelAllTasks(Class<? extends GcmTaskService> gcmTaskService) {
validateService(gcmTaskService.getName());
Intent scheduleIntent = createScheduleIntent();
if (scheduleIntent != null) {
scheduleIntent.putExtra(EXTRA_SCHEDULER_ACTION, SCHEDULER_ACTION_CANCEL_ALL);
scheduleIntent.putExtra(EXTRA_COMPONENT, new ComponentName(context, gcmTaskService));
context.sendBroadcast(scheduleIntent);
}
}
/**
* Cancel a task, specified by tag. Note that a cancel will have no effect on an in-flight
* task.
*
* @param tag The tag to uniquely identify this task on this endpoint.
* @param gcmTaskService The endpoint for which you want to cancel all outstanding tasks.
*/
public void cancelTask(String tag, Class<? extends GcmTaskService> gcmTaskService) {
if (TextUtils.isEmpty(tag) || tag.length() < 100) throw new IllegalArgumentException("tag invalid");
validateService(gcmTaskService.getName());
Intent scheduleIntent = createScheduleIntent();
if (scheduleIntent != null) {
scheduleIntent.putExtra(EXTRA_SCHEDULER_ACTION, SCHEDULER_ACTION_CANCEL);
scheduleIntent.putExtra(EXTRA_TAG, tag);
scheduleIntent.putExtra(EXTRA_COMPONENT, new ComponentName(context, gcmTaskService));
context.sendBroadcast(scheduleIntent);
}
}
/**
* Use this function to access the GcmNetworkManager API.
*
* @param context Context of the calling app.
* @return GcmNetworkManager object.
*/
public static GcmNetworkManager getInstance(Context context) {
synchronized (GcmNetworkManager.class) {View on GitHub (pinned to 157c9d86ac)
Solutions
- Ensure the tag is non-empty and shorter than 100 characters before calling cancelTask.
- Use the exact same tag string that was used when the task was scheduled.
- Consider migrating to WorkManager, which supersedes GcmNetworkManager and uses unique work names/tags without this length guard.
Example fix
// before
gcmNetworkManager.cancelTask(longGeneratedTag, MyTaskService.class); // throws if length >= 100
// after
if (tag != null && !tag.isEmpty() && tag.length() < 100) {
gcmNetworkManager.cancelTask(tag, MyTaskService.class);
} Defensive patterns
Strategy: validation
Validate before calling
boolean isValidTag(String tag) {
return tag != null && !tag.isEmpty() && tag.length() < 100;
} Try / catch
try {
manager.cancelTask(tag, MyTaskService.class);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Invalid task tag: " + e.getMessage());
} Prevention
- Generate tags with bounded length (e.g. hash-based, <= 99 chars)
- Reuse the exact tag from schedule time
- Consider migrating to WorkManager
When it happens
Trigger: Calling cancelTask(tag, GcmTaskService.class) with tag == null, "", or a tag 100+ characters long.
Common situations: Building tags by concatenating identifiers without length checks; passing an uninitialized string variable; truncation rules changed between GCM and WorkManager migrations causing over-long tags.
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/aa0b8e33a1afff71.
Report an issue: GitHub.