{"record":{"id":"281a766a7598e170","repo":"theonedev/onedev","slug":"reference-project-not-specified-referencestring","errorCode":null,"errorMessage":"Reference project not specified: <referenceString>","messagePattern":"Reference project not specified: <referenceString>","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java","lineNumber":73,"sourceCode":"\tprivate static Long parseReferenceNumber(String numberString) {\n\t\ttry {\n\t\t\treturn Long.valueOf(numberString);\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new ValidationException(\"Invalid reference number: \" + numberString);\n\t\t}\n\t}\n\n\tpublic static EntityReference of(String type, String referenceString, @Nullable Project currentProject) {\n\t\tvar projectService = OneDev.getInstance(ProjectService.class);\n\t\tvar index = referenceString.indexOf('#');\n\t\tif (index != -1) {\n\t\t\tvar projectPath = referenceString.substring(0, index);\n\t\t\tvar number = parseReferenceNumber(referenceString.substring(index + 1));\n\t\t\tif (projectPath.length() == 0) {\n\t\t\t\tif (currentProject != null)\n\t\t\t\t\treturn EntityReference.of(type, currentProject, number);\n\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}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java#L55-L91","documentation":"EntityReference.of parses references of the form '#number' or 'path#number'. When the path part is empty (string starts with '#') and no currentProject was supplied, there is no project context to resolve the number against, so a ValidationException 'Reference project not specified' is thrown.","triggerScenarios":"Calling EntityReference.of(type, \"#123\", null) — a project-less '#number' reference with currentProject == null.","commonSituations":"Background/system code that has no request-scoped project calling of() with a bare '#number' string; extracting a reference from user input and losing the current project context.","solutions":["Pass the current project as the third argument so '#number' can be resolved in that context.","Use a fully qualified reference like \"projectPath#number\" instead of a bare '#number'.","Use the '-number' (projectKey-number) form, e.g. \"PRJ-123\".","If no project can be determined, reject the input earlier with a clearer message."],"exampleFix":"// before\nEntityReference.of(\"issue\", \"#123\", null);\n// after\nEntityReference.of(\"issue\", \"#123\", currentProject); // or \"myproj#123\"","handlingStrategy":"validation","validationCode":"if (referenceString.startsWith(\"#\") && currentProject == null)\n    throw new IllegalArgumentException(\"Reference '\" + referenceString + \"' needs a current project\");","typeGuard":"boolean resolvableWithoutProject(String ref) {\n    return !ref.startsWith(\"#\");\n}","tryCatchPattern":"try {\n    EntityReference ref = EntityReference.of(\"issue\", input, currentProject);\n} catch (ValidationException e) {\n    if (e.getMessage().startsWith(\"Reference project not specified\")) {\n        // require a project context or ask user to qualify the reference\n    }\n}","preventionTips":["Always pass the current project when resolving user-supplied references.","Prefer fully qualified references (path#number) in stored/system-generated data.","Check currentProject for null before calling of() with bare '#number' inputs.","In background jobs, resolve the project explicitly instead of relying on implicit context."],"tags":["validation","entity-reference","missing-context"],"backgroundTag":"missing-required-argument","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"}