{"record":{"id":"8dc6fce2f864a495","repo":"theonedev/onedev","slug":"invalid-entity-reference-referencestring","errorCode":null,"errorMessage":"Invalid entity reference: <referenceString>","messagePattern":"Invalid entity reference: <referenceString>","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java","lineNumber":99,"sourceCode":"\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;\n\t\tvar otherReference = (EntityReference) other;\n\t\treturn new EqualsBuilder()\n\t\t\t\t.append(getType(), otherReference.getType())\n\t\t\t\t.append(projectId, otherReference.projectId)\n\t\t\t\t.append(number, otherReference.number)\n\t\t\t\t.isEquals();\n\t}\n\t\n\tpublic abstract String getType();","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java#L81-L117","documentation":"EntityReference.of() first tries the '#', then the '-' project-prefix forms, and finally attempts Long.valueOf(referenceString). If the string is neither a project-qualified reference nor a parseable number, NumberFormatException is caught and rethrown as ValidationException with \"Invalid entity reference\". The library requires references in one of: \"projectPath#number\", \"projectKey-number\", or a bare number.","triggerScenarios":"Calling EntityReference.of(type, referenceString, currentProject) with a string that has no '#' or '-' and is not a valid long, e.g. \"abc\", \"issue 12\", \"PR#\" with a non-numeric suffix, or \"KEY-abc\" where the part after '-' fails parseReferenceNumber.","commonSituations":"Users typing malformed references in markdown links or search boxes (\"issue #one\"); copy-pasted URLs with extra text; locale-formatted numbers; calling code passing an entire issue title instead of the reference.","solutions":["Fix the reference string to one of the accepted forms: \"projectPath#123\", \"KEY-123\", or a plain number like \"123\".","Trim whitespace and stray characters from the user input before parsing.","Catch ValidationException and surface a message showing the accepted reference formats.","Validate the string with a regex (e.g. ^[\\w./-]+#\\d+$ or ^\\w+-\\d+$ or ^\\d+$) before calling of()."],"exampleFix":"// before\nEntityReference.of(\"issue\", \"see issue #12\", project); // throws: not a number\n// after\nEntityReference.of(\"issue\", \"myProject#12\", project);","handlingStrategy":"validation","validationCode":"java.util.regex.Pattern REF = Pattern.compile(\"^([\\\\w./-]+#\\\\d+|\\\\w+-\\\\d+|\\\\d+)$\");\nif (!REF.matcher(referenceString).matches())\n    throw new IllegalArgumentException(\"Invalid reference format: \" + referenceString);","typeGuard":"boolean isValidReference(String s) {\n    return s.matches(\"^([\\\\w./-]+#\\\\d+|\\\\w+-\\\\d+|\\\\d+)$\");\n}","tryCatchPattern":"try {\n    EntityReference ref = EntityReference.of(type, referenceString, currentProject);\n} catch (ValidationException e) {\n    // show accepted formats: 'project#123', 'KEY-123', or '123'\n}","preventionTips":["Trim and sanitize user input before parsing.","Validate with a regex matching the three accepted forms.","Never pass free-text titles as reference strings.","Catch ValidationException and echo the expected formats."],"tags":["validation","parsing","entity-reference"],"backgroundTag":"invalid-argument-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"}