{"record":{"id":"297e125a45ecdc2f","repo":"theonedev/onedev","slug":"at-least-one-receiver-address-should-be-specified","errorCode":null,"errorMessage":"At least one receiver address should be specified","messagePattern":"At least one receiver address should be specified","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/mail/DefaultMailService.java","lineNumber":373,"sourceCode":"\t\t\tif (references != null) {\n\t\t\t\tString firstReference = StringUtils.substringBefore(references, \" \");\n\t\t\t\tMap<String, String> headers = CollectionUtils.newHashMap(\n\t\t\t\t\t\t\"References\", references, \n\t\t\t\t\t\t\"In-Reply-To\", firstReference, \n\t\t\t\t\t\t\"Thread-Index\", getThreadIndex(firstReference));\n\t\t\t\tfor (Map.Entry<String, String> entry: headers.entrySet()) {\n\t\t\t\t\tmessage.addHeader(entry.getKey(), createFoldedHeaderValue(entry.getKey(), entry.getValue()));\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (senderName == null || senderName.equalsIgnoreCase(\"onedev\")) \n\t\t\t\tsenderName = getQuoteMark();\n\t\t\telse \n\t\t\t\tsenderName += \" \" + getQuoteMark();\n\t\t\tmessage.setFrom(createInetAddress(senderAddress, senderName));\n\t\t\t\n\t\t\tif (toList.isEmpty() && ccList.isEmpty() && bccList.isEmpty())\n\t\t\t\tthrow new ExplicitException(\"At least one receiver address should be specified\");\n\t\t\t\n\t\t\tmessage.setRecipients(RecipientType.TO, \n\t\t\t\t\ttoList.stream().map(it->createInetAddress(it, null)).toArray(InternetAddress[]::new));\n\t\t\tmessage.setRecipients(RecipientType.CC, \n\t\t\t\t\tccList.stream().map(it->createInetAddress(it, null)).toArray(InternetAddress[]::new));\n\t\t\tmessage.setRecipients(RecipientType.BCC, \n\t\t\t\t\tbccList.stream().map(it->createInetAddress(it, null)).toArray(InternetAddress[]::new));\n\t\t\tif (replyAddress != null)\n\t\t\t\tmessage.setReplyTo(new InternetAddress[]{createInetAddress(replyAddress, null)});\n\n\t\t\tmessage.setSubject(subject);\n\t\t\tmessage.setContent(bodyPart);\n\n\t\t\tlogger.debug(\"Sending email (subject: {}, to: {}, cc: {}, bcc: {})... \", subject, toList, ccList, bccList);\n\n\t\t\ttry {\n\t\t\t\tsubmitToSendExecutor(smtpSetting.getConcurrency(), () -> {\n\t\t\t\t\ttry {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/mail/DefaultMailService.java#L355-L391","documentation":"DefaultMailService.sendMail refuses to send an email when the to, cc, and bcc address lists are all empty, throwing an ExplicitException because JavaMail requires at least one recipient for a message.","triggerScenarios":"Invoking sendMail (or a caller like sendMailAsync) with empty lists for to, cc, and bcc.","commonSituations":"Notification logic computing recipients dynamically (e.g. watchers, subscribers) that ends up with zero recipients after filtering; mail template/config producing no addresses.","solutions":["Guard the call site: skip sending when all recipient lists are empty instead of calling sendMail.","Fix the recipient-computation logic so at least one valid address is produced.","Add a default/agent address (e.g. admin) as fallback recipient."],"exampleFix":"// before\nmailService.sendMail(to, cc, bcc, subject, htmlBody, textBody, null, null, null);\n// after\nif (!to.isEmpty() || !cc.isEmpty() || !bcc.isEmpty())\n    mailService.sendMail(to, cc, bcc, subject, htmlBody, textBody, null, null, null);","handlingStrategy":"validation","validationCode":"if (to.isEmpty() && cc.isEmpty() && bcc.isEmpty()) return; // skip send","typeGuard":"boolean hasRecipient(List<String> to, List<String> cc, List<String> bcc) { return !to.isEmpty() || !cc.isEmpty() || !bcc.isEmpty(); }","tryCatchPattern":"try { mailService.sendMail(to, cc, bcc, ...); } catch (ExplicitException e) { log.warn(\"Skipping mail with no recipients\"); }","preventionTips":["Check recipient lists before calling send APIs","Handle the zero-watcher case in notification code","Log when recipients are filtered out to empty"],"tags":["email","mail","validation"],"backgroundTag":"empty-required-field","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}