{"record":{"id":"628e2876123bd3a3","repo":"microg/GmsCore","slug":"must-set-infectiousnesswhendayssinceonsetmissing","errorCode":null,"errorMessage":"Must set infectiousnessWhenDaysSinceOnsetMissing","messagePattern":"Must set infectiousnessWhenDaysSinceOnsetMissing","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java","lineNumber":84,"sourceCode":"\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\");\n                values[entry.getKey() + 14] = entry.getValue();\n            }\n            this.daysSinceOnsetToInfectiousness = Arrays.asList(values);\n            return this;","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java#L66-L102","documentation":"DiagnosisKeysDataMapping.Builder.build() throws IllegalStateException when infectiousnessWhenDaysSinceOnsetMissing is null. This field tells the API which infectiousness level to assign to keys lacking day-since-onset data, so it must be explicitly provided.","triggerScenarios":"Calling build() without calling setInfectiousnessWhenDaysSinceOnsetMissing(@Infectiousness int).","commonSituations":"The map and report type fallback are configured but the infectiousness fallback is overlooked, often because it is the last of three required setters.","solutions":["Call setInfectiousnessWhenDaysSinceOnsetMissing(Infectiousness.STANDARD) (or another concrete level) before build()","Audit the builder chain against the three required fields listed in build()","Add a shared config helper that constructs the mapping completely"],"exampleFix":"// before\nDiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping.Builder()\n    .setDaysSinceOnsetToInfectiousness(days)\n    .setReportTypeWhenMissing(ReportType.CONFIRMED_TEST)\n    .build();\n// after\nDiagnosisKeysDataMapping mapping = new DiagnosisKeysDataMapping.Builder()\n    .setDaysSinceOnsetToInfectiousness(days)\n    .setReportTypeWhenMissing(ReportType.CONFIRMED_TEST)\n    .setInfectiousnessWhenDaysSinceOnsetMissing(Infectiousness.STANDARD)\n    .build();","handlingStrategy":"validation","validationCode":"int infectiousnessWhenMissing = Infectiousness.STANDARD;\nbuilder.setDaysSinceOnsetToInfectiousness(days)\n    .setReportTypeWhenMissing(ReportType.CONFIRMED_TEST)\n    .setInfectiousnessWhenDaysSinceOnsetMissing(infectiousnessWhenMissing)\n    .build();","typeGuard":null,"tryCatchPattern":"try {\n    DiagnosisKeysDataMapping mapping = mappingBuilder.build();\n} catch (IllegalStateException e) {\n    Log.w(TAG, \"infectiousnessWhenDaysSinceOnsetMissing not set: \" + e.getMessage());\n}","preventionTips":["Treat the three builder fields as a required triple and set them together","Use Infectiousness.STANDARD as a safe default fallback","Add a startup assertion that builds the mapping successfully before exposure notifications are used"],"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-14T00:17:10.932Z"}