microg/GmsCore · error · IllegalArgumentException

invalid day since onset

Error message

invalid day since onset

What it means

setDaysSinceOnsetToInfectiousness throws IllegalArgumentException when any map key (day since onset) is greater than 14. Valid day offsets run from -14 to +14; anything beyond 14 falls outside the infectiousness window the API accepts.

Source

Thrown at play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java:98

                throw new IllegalStateException("Must set daysSinceOnsetToInfectiousness");
            if (reportTypeWhenMissing == ReportType.UNKNOWN)
                throw new IllegalStateException("Must set reportTypeWhenMissing");
            if (infectiousnessWhenDaysSinceOnsetMissing == null)
                throw new IllegalStateException("Must set infectiousnessWhenDaysSinceOnsetMissing");
            DiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping();
            mapping.daysSinceOnsetToInfectiousness = new ArrayList<>(daysSinceOnsetToInfectiousness);
            mapping.reportTypeWhenMissing = reportTypeWhenMissing;
            mapping.infectiousnessWhenDaysSinceOnsetMissing = infectiousnessWhenDaysSinceOnsetMissing;
            return mapping;
        }

        public DiagnosisKeysDataMappingBuilder setDaysSinceOnsetToInfectiousness(Map<Integer, Integer> daysSinceOnsetToInfectiousness) {
            if (daysSinceOnsetToInfectiousness.size() > MAX_DAYS)
                throw new IllegalArgumentException("daysSinceOnsetToInfectiousness exceeds " + MAX_DAYS + " days");
            Integer[] values = new Integer[MAX_DAYS];
            Arrays.fill(values, 0);
            for (Map.Entry<Integer, Integer> entry : daysSinceOnsetToInfectiousness.entrySet()) {
                if (entry.getKey() > 14) throw new IllegalArgumentException("invalid day since onset");
                values[entry.getKey() + 14] = entry.getValue();
            }
            this.daysSinceOnsetToInfectiousness = Arrays.asList(values);
            return this;
        }

        public DiagnosisKeysDataMappingBuilder setInfectiousnessWhenDaysSinceOnsetMissing(@Infectiousness int infectiousnessWhenDaysSinceOnsetMissing) {
            this.infectiousnessWhenDaysSinceOnsetMissing = infectiousnessWhenDaysSinceOnsetMissing;
            return this;
        }

        public DiagnosisKeysDataMappingBuilder setReportTypeWhenMissing(@ReportType int reportTypeWhenMissing) {
            this.reportTypeWhenMissing = reportTypeWhenMissing;
            return this;
        }
    }

    public static final Creator<DiagnosisKeysDataMapping> CREATOR = new AutoCreator<>(DiagnosisKeysDataMapping.class);

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Filter map keys to the range -14..14 before calling the setter
  2. Check offset computation logic (e.g. chronology units) for off-by-one errors
  3. Ensure keys are day offsets relative to onset, not absolute dates or indices >14

Example fix

// before
for (int day = 0; day <= 20; day++) map.put(day, Infectiousness.STANDARD);
builder.setDaysSinceOnsetToInfectiousness(map);
// after
for (int day = -14; day <= 14; day++) map.put(day, Infectiousness.STANDARD);
builder.setDaysSinceOnsetToInfectiousness(map);
Defensive patterns

Strategy: validation

Validate before calling

for (Integer day : daysMap.keySet()) {
    if (day < -14 || day > 14) {
        throw new IllegalArgumentException("day offset must be in [-14, 14], got " + day);
    }
}
builder.setDaysSinceOnsetToInfectiousness(daysMap);

Try / catch

try {
    builder.setDaysSinceOnsetToInfectiousness(daysMap);
} catch (IllegalArgumentException e) {
    Log.w(TAG, "Invalid day offset: " + e.getMessage());
}

Prevention

When it happens

Trigger: Passing a map containing a key > 14 to DiagnosisKeysDataMapping.Builder.setDaysSinceOnsetToInfectiousness.

Common situations: Off-by-one errors when computing day offsets, or indexing days after symptom onset starting at 15 or later; also bugs that store timestamps instead of day offsets as keys.

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


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