{"record":{"id":"62e2be92d6c83d6b","repo":"theonedev/onedev","slug":"invalid-commit-id","errorCode":null,"errorMessage":"Invalid commit id","messagePattern":"Invalid commit id","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/CommitInput.java","lineNumber":36,"sourceCode":"\t\tinputSpec.appendField(buffer, index, \"String\");\n\t\tinputSpec.appendCommonAnnotations(buffer, index);\n\t\tbuffer.append(\"    @CommitHash\\n\");\n\t\tif (!inputSpec.isAllowEmpty())\n\t\t\tbuffer.append(\"    @NotEmpty\\n\");\n\t\tinputSpec.appendMethods(buffer, index, \"String\", 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\tif (ObjectId.isId(value))\n\t\t\t\treturn value;\n\t\t\telse\n\t\t\t\tthrow new ValidationException(\"Invalid commit id\");\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 String)\n\t\t\treturn Lists.newArrayList((String) value);\n\t\telse\n\t\t\treturn new ArrayList<>();\n\t}\n\t\n}\n","sourceCodeStart":18,"sourceCodeEnd":50,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/CommitInput.java#L18-L50","documentation":"CommitInput converts input strings into commit ids for commit-type input parameters. A value is valid only if JGit's ObjectId.isId accepts it (40-char hex SHA-1). Any other single value is rejected with ValidationException('Invalid commit id').","triggerScenarios":"convertToObject receives a single string that is not a valid git object id — e.g. a branch name, short SHA, 'HEAD', or a SHA with invalid characters/length.","commonSituations":"Typing a branch name or tag instead of the full commit hash; pasting an abbreviated SHA (7-8 chars); parameter substitution producing an empty or malformed value.","solutions":["Provide the full 40-character hexadecimal commit SHA.","Resolve the branch/tag to its full SHA first (git rev-parse <ref>) and use that value.","Fix parameter expressions so they resolve to a full SHA rather than a ref name.","Extend the abbreviated SHA before entering it."],"exampleFix":"// before\nvalue: \"main\"\n// after\nvalue: \"3f2a9c8d1e0b7a6f5c4d3e2f1a0b9c8d7e6f5a4b\"","handlingStrategy":"validation","validationCode":"// Validate a full 40-char hex SHA before submitting\nif (!/^[0-9a-fA-F]{40}$/.test(commitValue)) {\n  throw new Error(\"Provide a full commit SHA (git rev-parse <ref>)\");\n}","typeGuard":"boolean isCommitId(String v) {\n  return v != null && org.eclipse.jgit.lib.ObjectId.isId(v.trim());\n}","tryCatchPattern":"try {\n    Object commit = CommitInput.convertToObject(strings);\n} catch (ValidationException e) {\n    // prompt user for full 40-char SHA\n}","preventionTips":["Run git rev-parse <ref> to expand branches/tags to full SHAs.","Never enter short SHAs, branch names, or HEAD directly.","Verify parameter substitutions resolve to SHAs, not ref names."],"tags":["git","validation","input","commit"],"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"}