{"record":{"id":"1ed90b21ef5681d4","repo":"microg/GmsCore","slug":"must-set-dayssinceonsettoinfectiousness","errorCode":null,"errorMessage":"Must set daysSinceOnsetToInfectiousness","messagePattern":"Must set daysSinceOnsetToInfectiousness","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java","lineNumber":80,"sourceCode":"     */\n    public int getReportTypeWhenMissing() {\n        return reportTypeWhenMissing;\n    }\n\n    /**\n     * A builder for {@link DiagnosisKeysDataMapping}.\n     */\n    public static class DiagnosisKeysDataMappingBuilder {\n        private final static int MAX_DAYS = 29;\n        private List<Integer> daysSinceOnsetToInfectiousness;\n        @ReportType\n        private int reportTypeWhenMissing = ReportType.UNKNOWN;\n        @Infectiousness\n        private Integer infectiousnessWhenDaysSinceOnsetMissing;\n\n        public DiagnosisKeysDataMapping build() {\n            if (daysSinceOnsetToInfectiousness == null)\n                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\");","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java#L62-L98","documentation":"DiagnosisKeysDataMapping.Builder.build() requires daysSinceOnsetToInfectiousness to be set; it maps days-since-onset offsets to infectiousness levels when diagnosis keys are uploaded. The builder throws IllegalStateException to stop a mapping object with no map from being submitted to the Exposure Notification API.","triggerScenarios":"Calling DiagnosisKeysDataMapping.Builder.build() without calling setDaysSinceOnsetToInfectiousness(Map<Integer,Integer>).","commonSituations":"App authors assemble the mapping partially during onboarding configuration and leave the map unset, or assume the builder supplies a default mapping.","solutions":["Call setDaysSinceOnsetToInfectiousness with a map of day offsets (-14..14) to @Infectiousness values before build()","If you intentionally want defaults, still provide the map (empty or fully populated) so validation passes","Ensure the mapping initialization code path always runs (e.g. first-launch setup)"],"exampleFix":"// before\nDiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping.Builder().build();\n// after\nMap<Integer, Integer> days = new HashMap<>();\ndays.put(-14, Infectiousness.HIGH);\ndays.put(0, Infectiousness.HIGH);\ndays.put(14, Infectiousness.HIGH);\nDiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping.Builder()\n    .setDaysSinceOnsetToInfectiousness(days)\n    .setReportTypeWhenMissing(ReportType.CONFIRMED_TEST)\n    .setInfectiousnessWhenDaysSinceOnsetMissing(Infectiousness.STANDARD)\n    .build();","handlingStrategy":"validation","validationCode":"if (daysSinceOnsetToInfectiousness == null) {\n    daysSinceOnsetToInfectiousness = Collections.emptyMap();\n}\nDiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping.Builder()\n    .setDaysSinceOnsetToInfectiousness(daysSinceOnsetToInfectiousness)\n    .setReportTypeWhenMissing(ReportType.CONFIRMED_TEST)\n    .setInfectiousnessWhenDaysSinceOnsetMissing(Infectiousness.STANDARD)\n    .build();","typeGuard":null,"tryCatchPattern":"try {\n    DiagnosisKeysDataMapping mapping = mappingBuilder.build();\n} catch (IllegalStateException e) {\n    Log.w(TAG, \"Incomplete DiagnosisKeysDataMapping: \" + e.getMessage());\n}","preventionTips":["Always set all three required fields (map, reportTypeWhenMissing, infectiousnessWhenDaysSinceOnsetMissing)","Run mapping setup during app onboarding, not lazily at key-upload time","Unit-test the mapping builder with representative day maps"],"tags":["java","builder-validation","exposure-notification"],"backgroundTag":"missing-required-argument","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"}