{"record":{"id":"15f367ee8414fdb0","repo":"microg/GmsCore","slug":"invalid-day-since-onset","errorCode":null,"errorMessage":"invalid day since onset","messagePattern":"invalid day since onset","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java","lineNumber":98,"sourceCode":"                throw new IllegalStateException(\"Must set daysSinceOnsetToInfectiousness\");\n            if (reportTypeWhenMissing == ReportType.UNKNOWN)\n                throw new IllegalStateException(\"Must set reportTypeWhenMissing\");\n            if (infectiousnessWhenDaysSinceOnsetMissing == null)\n                throw new IllegalStateException(\"Must set infectiousnessWhenDaysSinceOnsetMissing\");\n            DiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping();\n            mapping.daysSinceOnsetToInfectiousness = new ArrayList<>(daysSinceOnsetToInfectiousness);\n            mapping.reportTypeWhenMissing = reportTypeWhenMissing;\n            mapping.infectiousnessWhenDaysSinceOnsetMissing = infectiousnessWhenDaysSinceOnsetMissing;\n            return mapping;\n        }\n\n        public DiagnosisKeysDataMappingBuilder setDaysSinceOnsetToInfectiousness(Map<Integer, Integer> daysSinceOnsetToInfectiousness) {\n            if (daysSinceOnsetToInfectiousness.size() > MAX_DAYS)\n                throw new IllegalArgumentException(\"daysSinceOnsetToInfectiousness exceeds \" + MAX_DAYS + \" days\");\n            Integer[] values = new Integer[MAX_DAYS];\n            Arrays.fill(values, 0);\n            for (Map.Entry<Integer, Integer> entry : daysSinceOnsetToInfectiousness.entrySet()) {\n                if (entry.getKey() > 14) throw new IllegalArgumentException(\"invalid day since onset\");\n                values[entry.getKey() + 14] = entry.getValue();\n            }\n            this.daysSinceOnsetToInfectiousness = Arrays.asList(values);\n            return this;\n        }\n\n        public DiagnosisKeysDataMappingBuilder setInfectiousnessWhenDaysSinceOnsetMissing(@Infectiousness int infectiousnessWhenDaysSinceOnsetMissing) {\n            this.infectiousnessWhenDaysSinceOnsetMissing = infectiousnessWhenDaysSinceOnsetMissing;\n            return this;\n        }\n\n        public DiagnosisKeysDataMappingBuilder setReportTypeWhenMissing(@ReportType int reportTypeWhenMissing) {\n            this.reportTypeWhenMissing = reportTypeWhenMissing;\n            return this;\n        }\n    }\n\n    public static final Creator<DiagnosisKeysDataMapping> CREATOR = new AutoCreator<>(DiagnosisKeysDataMapping.class);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java#L80-L116","documentation":"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.","triggerScenarios":"Passing a map containing a key > 14 to DiagnosisKeysDataMapping.Builder.setDaysSinceOnsetToInfectiousness.","commonSituations":"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.","solutions":["Filter map keys to the range -14..14 before calling the setter","Check offset computation logic (e.g. chronology units) for off-by-one errors","Ensure keys are day offsets relative to onset, not absolute dates or indices >14"],"exampleFix":"// before\nfor (int day = 0; day <= 20; day++) map.put(day, Infectiousness.STANDARD);\nbuilder.setDaysSinceOnsetToInfectiousness(map);\n// after\nfor (int day = -14; day <= 14; day++) map.put(day, Infectiousness.STANDARD);\nbuilder.setDaysSinceOnsetToInfectiousness(map);","handlingStrategy":"validation","validationCode":"for (Integer day : daysMap.keySet()) {\n    if (day < -14 || day > 14) {\n        throw new IllegalArgumentException(\"day offset must be in [-14, 14], got \" + day);\n    }\n}\nbuilder.setDaysSinceOnsetToInfectiousness(daysMap);","typeGuard":null,"tryCatchPattern":"try {\n    builder.setDaysSinceOnsetToInfectiousness(daysMap);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Invalid day offset: \" + e.getMessage());\n}","preventionTips":["Clamp or filter offsets to [-14, 14] before insertion","Double-check index arithmetic when converting dates to day offsets","Unit-test edge days -14 and 14 in map-building code"],"tags":["java","argument-validation","exposure-notification"],"backgroundTag":"invalid-argument-value","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}