{"record":{"id":"8b0a23ab75b8d2ce","repo":"theonedev/onedev","slug":"reference-project-not-found-with-key-projectkey","errorCode":null,"errorMessage":"Reference project not found with key: <projectKey>","messagePattern":"Reference project not found with key: <projectKey>","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java","lineNumber":90,"sourceCode":"\t\t\t\telse\n\t\t\t\t\tthrow new ValidationException(\"Reference project not specified: \" + referenceString);\n\t\t\t} else {\n\t\t\t\tvar project = projectService.findByPath(projectPath);\n\t\t\t\tif (project != null)\n\t\t\t\t\treturn EntityReference.of(type, project, number);\n\t\t\t\telse\n\t\t\t\t\tthrow new ValidationException(\"Reference project not found: \" + projectPath);\n\t\t\t}\n\t\t}\n\t\tindex = referenceString.indexOf('-');\n\t\tif (index != -1) {\n\t\t\tvar projectKey = referenceString.substring(0, index);\n\t\t\tvar number = parseReferenceNumber(referenceString.substring(index + 1));\n\t\t\tvar project = projectService.findByKey(projectKey);\n\t\t\tif (project != null)\n\t\t\t\treturn EntityReference.of(type, project, number);\n\t\t\telse\n\t\t\t\tthrow new ValidationException(\"Reference project not found with key: \" + projectKey);\n\t\t}\n\t\ttry {\n\t\t\tvar number = Long.valueOf(referenceString);\n\t\t\tif (currentProject != null)\n\t\t\t\treturn EntityReference.of(type, currentProject, number);\n\t\t\telse\n\t\t\t\tthrow new ValidationException(\"Reference project not specified: \" + referenceString);\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new ValidationException(\"Invalid entity reference: \" + referenceString);\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic boolean equals(Object other) {\n\t\tif (!(other instanceof EntityReference))\n\t\t\treturn false;\n\t\tif (this == other)\n\t\t\treturn true;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java#L72-L108","documentation":"EntityReference.of resolves the 'KEY-number' form (e.g. \"PRJ-123\") via projectService.findByKey(projectKey). If no project matches the key, a ValidationException 'Reference project not found with key' is thrown. The syntax is valid but no project has that key.","triggerScenarios":"Calling EntityReference.of(type, \"XYZ-42\", ...) where findByKey(\"XYZ\") returns null — wrong key, project deleted, or key changed.","commonSituations":"References to projects whose key was changed; typos in the key portion; external tools generating references from stale configuration.","solutions":["Fix the project key in the reference to match an existing project.","Verify the project's key was not changed (project settings) or the project deleted.","If only the path is known, use the \"path#number\" form instead.","Look the project up yourself first and construct EntityReference.of(type, project, number)."],"exampleFix":"// before\nEntityReference.of(\"issue\", \"WRONG-12\", null);\n// after\nEntityReference.of(\"issue\", \"PROJ-12\", null);","handlingStrategy":"validation","validationCode":"int i = referenceString.indexOf('-');\nString key = i > 0 ? referenceString.substring(0, i) : null;\nif (key != null && projectService.findByKey(key) == null)\n    throw new IllegalArgumentException(\"Unknown project key: \" + key);","typeGuard":null,"tryCatchPattern":"try {\n    EntityReference ref = EntityReference.of(\"issue\", input, currentProject);\n} catch (ValidationException e) {\n    if (e.getMessage().startsWith(\"Reference project not found with key\")) {\n        // look up valid project keys and inform the user\n    }\n}","preventionTips":["Fetch the current list of project keys when building tools that generate KEY-number references.","Avoid hardcoding project keys in external configs; look them up dynamically.","Watch for project key changes and update generated references accordingly.","When unsure, use the numeric project id or path form instead of the key form."],"tags":["entity-reference","project-not-found","validation"],"backgroundTag":"resource-not-found","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"}