theonedev/onedev · error · ExplicitException
Invalid LFS object id
Error message
Invalid LFS object id
What it means
LfsObject's constructor validates that the objectId matches OBJECT_ID_PATTERN (an OID/SHA-like pattern, see isValidObjectId) and throws ExplicitException("Invalid LFS object id") otherwise. This guards the LFS object storage against malformed identifiers.
Source
Thrown at server-core/src/main/java/io/onedev/server/git/LfsObject.java:49
public class LfsObject implements Serializable {
private static final long serialVersionUID = 1L;
/**
* A Git LFS oid is a lowercase hex SHA-256 digest (64 characters). Anything
* else is invalid and must never be used as a filesystem path component, as
* the on-disk layout below derives the storage path directly from it.
*/
private static final Pattern OBJECT_ID_PATTERN = Pattern.compile("[0-9a-f]{64}");
private final Long projectId;
private final String objectId;
public LfsObject(Long projectId, String objectId) {
if (!isValidObjectId(objectId))
throw new ExplicitException("Invalid LFS object id");
this.projectId = projectId;
this.objectId = objectId;
}
public static boolean isValidObjectId(@Nullable String objectId) {
return objectId != null && OBJECT_ID_PATTERN.matcher(objectId).matches();
}
public Long getProjectId() {
return projectId;
}
public String getObjectId() {
return objectId;
}
private ProjectService getProjectService() {
return OneDev.getInstance(ProjectService.class);View on GitHub (pinned to d44925c47c)
Solutions
- Validate with LfsObject.isValidObjectId(id) before constructing and surface a clear message to the caller
- Fix the source of the id — re-read the LFS pointer file or the client request that produced the malformed OID
- Re-push the affected files with a working git-lfs client if pointer files are corrupted
Example fix
// before
new LfsObject(projectId, somePathSegment); // may throw
// after
if (LfsObject.isValidObjectId(oid)) {
new LfsObject(projectId, oid);
} else {
throw new IllegalArgumentException("Malformed LFS OID: " + oid);
} Defensive patterns
Strategy: validation
Validate before calling
// call before constructing
if (!LfsObject.isValidObjectId(oid))
throw new IllegalArgumentException("LFS OID must match OID pattern: " + oid); Type guard
boolean isLfsOid(String s) {
return s != null && s.length() == 64 && s.chars().allMatch(c -> (c>='0'&&c<='9')||(c>='a'&&c<='f'));
} Try / catch
try {
LfsObject obj = new LfsObject(projectId, oid);
} catch (ExplicitException e) {
if ("Invalid LFS object id".equals(e.getMessage())) {
// re-read pointer file / request param
}
} Prevention
- Parse OIDs only from well-formed LFS pointer files
- Sanitize client-supplied path/query components before using as OID
- Log the raw id on failure to spot truncation early
When it happens
Trigger: Constructing new LfsObject(projectId, objectId) with a null, empty, or non-hex id that does not satisfy isValidObjectId — e.g. an id read from a malformed LFS pointer file, a truncated request parameter, or a client-supplied path component.
Common situations: Corrupt or hand-edited LFS pointer files; API/git clients sending wrong query params; attempting to look up LFS objects with a Git blob SHA or a different hash length instead of the LFS OID.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Title is required
- Count should not be greater than ${RestConstants.MAX_PAGE_SI
- ${e.getMessage()}
- State is required
- Issue ${issueReference} is not in current project
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/8b9a12afab408bbd.
Report an issue: GitHub.