{"record":{"id":"473b980f22806c76","repo":"theonedev/onedev","slug":"invalid-pull-request-id-number","errorCode":null,"errorMessage":"Invalid pull request id/number","messagePattern":"Invalid pull request id/number","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/PullRequestChoiceInput.java","lineNumber":34,"sourceCode":"\t\tinputSpec.appendField(buffer, index, \"Long\");\n\t\tinputSpec.appendCommonAnnotations(buffer, index);\n\t\tif (!inputSpec.isAllowEmpty())\n\t\t\tbuffer.append(\"    @NotNull\\n\");\n\t\tbuffer.append(\"    @PullRequestChoice(useNumber=true)\\n\");\n\t\tinputSpec.appendMethods(buffer, index, \"Long\", null, null);\n\t\t\n\t\treturn buffer.toString();\n\t}\n\n\tpublic static Object convertToObject(List<String> strings) {\n\t\tif (strings.size() == 0) {\n\t\t\treturn null;\n\t\t} else if (strings.size() == 1) {\n\t\t\tString value = strings.iterator().next();\n\t\t\ttry {\n\t\t\t\treturn Long.valueOf(value);\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new ValidationException(\"Invalid pull request id/number\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new ValidationException(\"Not eligible for multi-value\");\n\t\t}\n\t}\n\n\tpublic static List<String> convertToStrings(Object value) {\n\t\tif (value instanceof Long)\n\t\t\treturn Lists.newArrayList(value.toString());\n\t\telse\n\t\t\treturn new ArrayList<>();\n\t}\n\n}\n","sourceCodeStart":16,"sourceCodeEnd":49,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/PullRequestChoiceInput.java#L16-L49","documentation":"PullRequestChoiceInput.convertToObject parses a single user-supplied string into a Long pull request id/number. If the string cannot be parsed as a Long, a ValidationException with 'Invalid pull request id/number' is thrown. This input type accepts only one value and only numeric pull request ids/numbers.","triggerScenarios":"Calling PullRequestChoiceInput.convertToObject(List<String>) with a single-element list whose value is not parseable by Long.valueOf, e.g. a branch name, a URL like 'https://host/project/pulls/12', or a value with whitespace/typos.","commonSituations":"Buildspec job or CI/CD job input bound to a pull request choice where the user hand-typed a PR title or URL instead of the number; a script passing the full PR reference (e.g. '#12' or 'pulls/12') instead of the bare number; stale spec files after OneDev version changes.","solutions":["Pass only the bare numeric pull request id or number (e.g. '12', not '#12' or the PR URL).","Strip non-numeric prefixes/suffixes before calling convertToObject, or trim whitespace.","Use the UI 'Pull Request' input selector rather than hand-editing the spec value.","Validate the value with a regex ^\\d+$ before invoking convertToObject."],"exampleFix":"// before\nString pr = \"https://onedev.example.com/proj/pulls/12\";\nObject value = PullRequestChoiceInput.convertToObject(Lists.newArrayList(pr));\n\n// after\nString pr = \"12\"; // bare number extracted from the URL\nObject value = PullRequestChoiceInput.convertToObject(Lists.newArrayList(pr));","handlingStrategy":"validation","validationCode":"boolean validPrValue(String s) {\n    return s != null && s.trim().matches(\"\\\\d+\");\n}\n// call convertToObject only if validPrValue(value)","typeGuard":"boolean isNumeric(String s) {\n    return s != null && s.matches(\"\\\\d+\");\n}","tryCatchPattern":"try {\n    Object pr = PullRequestChoiceInput.convertToObject(Lists.newArrayList(value));\n} catch (ValidationException e) {\n    // report/fix: value must be a bare numeric pull request id/number\n}","preventionTips":["Always pass bare numeric PR ids/numbers, never URLs, titles, or '#12' forms.","Trim and sanitize input strings before conversion.","Use the UI pull-request picker instead of hand-editing spec values."],"tags":["validation","buildspec","input-parsing"],"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-14T00:17:10.932Z"}