{"record":{"id":"6d53b4d73efb3422","repo":"theonedev/onedev","slug":"invalid-reference-number-numberstring","errorCode":null,"errorMessage":"Invalid reference number: <numberString>","messagePattern":"Invalid reference number: <numberString>","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java","lineNumber":59,"sourceCode":"\t\treturn number;\n\t}\n\n\tpublic static EntityReference of(String type, Project project, Long number) {\n\t\tif (type.length() == 0 || type.equalsIgnoreCase(IssueReference.TYPE))\n\t\t\treturn new IssueReference(project, number);\n\t\telse if (type.equalsIgnoreCase(BuildReference.TYPE))\n\t\t\treturn new BuildReference(project, number);\n\t\telse if (type.equalsIgnoreCase(WorkspaceReference.TYPE))\n\t\t\treturn new WorkspaceReference(project, number);\n\t\telse\n\t\t\treturn new PullRequestReference(project, number);\n\t}\n\n\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);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java#L41-L77","documentation":"EntityReference.parseReferenceNumber converts the text after '#' (or '-' in KEY-number form) into a Long entity number. If the segment is not a plain integer, a ValidationException with 'Invalid reference number' is thrown. This means the reference string was recognized structurally but its number part is malformed.","triggerScenarios":"Calling EntityReference.of(type, \"#abc\") or \"PRJ-a1b2\", or parsing strings like \"#12x34\" / \"# 5\" where the substring after the separator is not parseable by Long.valueOf.","commonSituations":"Typos in issue/PR references; users pasting text with trailing characters; programmatic string concatenation producing e.g. \"#\" + null; references copied from URLs with extra suffixes.","solutions":["Correct the reference string so the number after '#' or '-' is a plain integer (e.g. \"#123\", \"PROJ-456\").","Validate/strip the number portion before calling EntityReference.of.","If input comes from users, parse defensively and show a validation message.","If the whole string is just a bare number, ensure no stray characters are appended."],"exampleFix":"// before\nEntityReference.of(\"issue\", \"#12a\", project);\n// after\nEntityReference.of(\"issue\", \"#12\", project);","handlingStrategy":"validation","validationCode":"if (!referenceString.matches(\"(?:[A-Za-z0-9_/.-]+)?[#-]\\\\d+\"))\n    throw new IllegalArgumentException(\"Malformed reference: \" + referenceString);","typeGuard":"boolean isWellFormedReference(String s) {\n    int i = s.indexOf('#');\n    if (i == -1) i = s.indexOf('-');\n    if (i == -1 || i == s.length() - 1) return false;\n    return s.substring(i + 1).chars().allMatch(Character::isDigit);\n}","tryCatchPattern":"try {\n    EntityReference ref = EntityReference.of(\"issue\", input, project);\n} catch (ValidationException e) {\n    // show e.getMessage() to the user as an input validation error\n}","preventionTips":["Validate reference strings with a regex before parsing.","Trim/normalize user input to strip stray characters.","Never build references by concatenating possibly-null or non-numeric values.","Show a clear input hint (e.g. \"issue #123 or PROJ-123\") where users type references."],"tags":["validation","parsing","entity-reference"],"backgroundTag":"invalid-identifier-format","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"}