{"record":{"id":"75a89c5be2576518","repo":"microg/GmsCore","slug":"must-set-reporttypewhenmissing","errorCode":null,"errorMessage":"Must set reportTypeWhenMissing","messagePattern":"Must set reportTypeWhenMissing","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java","lineNumber":82,"sourceCode":"        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\");\n                values[entry.getKey() + 14] = entry.getValue();\n            }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeysDataMapping.java#L64-L100","documentation":"DiagnosisKeysDataMapping.Builder.build() throws IllegalStateException when reportTypeWhenMissing is still ReportType.UNKNOWN (its default). The API needs to know which report type to assume when a key has no report type; UNKNOWN is treated as 'not configured'.","triggerScenarios":"Calling build() without calling setReportTypeWhenMissing(@ReportType int) — or explicitly passing ReportType.UNKNOWN.","commonSituations":"Developers set the infectiousness fallback but forget the report-type fallback, or mistakenly pass ReportType.UNKNOWN thinking it means 'any'.","solutions":["Call setReportTypeWhenMissing with a concrete type such as ReportType.CONFIRMED_TEST or ReportType.CONFIRMED_CLINICAL_DIAGNOSIS","Do not pass ReportType.UNKNOWN; it is only the sentinel default","Set all three required fields (map, reportTypeWhenMissing, infectiousnessWhenDaysSinceOnsetMissing) together"],"exampleFix":"// before\nbuilder.setReportTypeWhenMissing(ReportType.UNKNOWN);\n// after\nbuilder.setReportTypeWhenMissing(ReportType.CONFIRMED_TEST);","handlingStrategy":"validation","validationCode":"if (reportTypeWhenMissing == ReportType.UNKNOWN) {\n    reportTypeWhenMissing = ReportType.CONFIRMED_TEST; // sensible default\n}\nbuilder.setReportTypeWhenMissing(reportTypeWhenMissing);","typeGuard":null,"tryCatchPattern":"try {\n    DiagnosisKeysDataMapping mapping = mappingBuilder.build();\n} catch (IllegalStateException e) {\n    Log.w(TAG, \"reportTypeWhenMissing not configured: \" + e.getMessage());\n}","preventionTips":["Never pass ReportType.UNKNOWN as the fallback value","Choose the fallback report type as a product decision, not a default constant","Log the configured mapping at startup to catch misconfiguration early"],"tags":["java","builder-validation","exposure-notification","enum"],"backgroundTag":"invalid-enum-value","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"}