{"record":{"id":"3f358422ae6418b9","repo":"theonedev/onedev","slug":"link-spec-not-allowed-to-link-to-the-target-issue","errorCode":null,"errorMessage":"Link spec not allowed to link to the target issue","messagePattern":"Link spec not allowed to link to the target issue","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/model/IssueLink.java","lineNumber":97,"sourceCode":"\t}\n\n\tpublic void setPosition(int position) {\n\t\tthis.position = position;\n\t}\n\n\tpublic void validate() {\n\t\tif (getSource().equals(getTarget()))\n\t\t\tthrow new ValidationException(\"Cannot link to self\");\n\t\tif (getSpec().getOpposite() != null) {\n\t\t\tif (getSource().getTargetLinks().stream()\n\t\t\t\t\t.anyMatch(it -> it.getSpec().equals(getSpec()) && it.getTarget().equals(getTarget())))\n\t\t\t\tthrow new ValidationException(\"Source issue already linked to target issue via specified link spec\");\n\t\t\tif (!getSpec().isMultiple()\n\t\t\t\t\t&& getSource().getTargetLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))\n\t\t\t\tthrow new ValidationException(\n\t\t\t\t\t\t\"Link spec is not multiple and the source issue is already linked to another issue via this link spec\");\n\t\t\tif (!getSpec().getParsedIssueQuery(getSource().getProject()).matches(getTarget()))\n\t\t\t\tthrow new ValidationException(\"Link spec not allowed to link to the target issue\");\n\t\t\tif (!getSpec().getOpposite().isMultiple()\n\t\t\t\t\t&& getTarget().getSourceLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))\n\t\t\t\tthrow new ValidationException(\n\t\t\t\t\t\t\"Opposite side of link spec is not multiple and the target issue is already linked to another issue via this link spec\");\n\t\t\tif (!getSpec().getOpposite().getParsedIssueQuery(getSource().getProject())\n\t\t\t\t\t.matches(getSource()))\n\t\t\t\tthrow new ValidationException(\"Opposite side of link spec not allowed to link to the source issue\");\n\t\t} else {\n\t\t\tif (getSource().getLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())\n\t\t\t\t\t&& it.getLinked(getSource()).equals(getTarget())))\n\t\t\t\tthrow new ValidationException(\"Specified issues already linked via specified link spec\");\n\t\t\tif (!getSpec().isMultiple()\n\t\t\t\t\t&& getSource().getLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))\n\t\t\t\tthrow new ValidationException(\n\t\t\t\t\t\t\"Link spec is not multiple and source issue is already linked to another issue via this link spec\");\n\t\t\tvar parsedIssueQuery = getSpec().getParsedIssueQuery(getSource().getProject());\n\t\t\tif (!parsedIssueQuery.matches(getSource()) || !parsedIssueQuery.matches(getTarget()))\n\t\t\t\tthrow new ValidationException(\"Link spec not allowed to link specified issues\");","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/model/IssueLink.java#L79-L115","documentation":"IssueLink.validate() checks that both ends of a bidirectional link satisfy the spec's issue queries. Each LinkSpec can define a parsed issue query restricting which issues may be linked; this error is thrown when the target issue does not match getSpec().getParsedIssueQuery(source issue's project). The spec intentionally disallows this link.","triggerScenarios":"createLink called where the spec (with an opposite) defines an issue query and getTarget() fails that query when evaluated in the source issue's project.","commonSituations":"Admin scoped the link spec to e.g. 'State is Requirement' but the user links a bug; issues live in different projects and the query evaluates against the source's project; the query was tightened after the UI allowed the link to be drafted.","solutions":["Verify the target issue matches the link spec's allowed-issue query (Administration > Links) and pick a target that satisfies it.","Adjust the spec's issue query to include the states/projects/attributes of the issues you want to link.","Link via a different spec whose query permits the target issue."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var query = link.getSpec().getParsedIssueQuery(link.getSource().getProject());\nif (!query.matches(link.getTarget())) throw new IllegalStateException(\"target not allowed by spec query\");","typeGuard":null,"tryCatchPattern":"try { IssueLink.createLink(link); } catch (ValidationException e) { // show which spec/query rejected the target }","preventionTips":["Review the link spec's issue query before linking","Filter candidate targets with the spec's query in the UI beforehand","Keep spec queries updated when issue workflows change"],"tags":["issue-links","issue-query","validation"],"backgroundTag":"invalid-argument-value","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"}