theonedev/onedev · error · NotFoundException

Unable to find commit associated with object id: ${revId}

Error message

Unable to find commit associated with object id: ${revId}

What it means

Project.getCommit(revId, mustExist) loads a RevCommit for an ObjectId via the git service (cached). When mustExist is true and the object id does not correspond to any commit in the repository, a NotFoundException is thrown. This differs from error 348: here the id format is valid but the commit object itself is absent (or is not a commit).

Source

Thrown at server-core/src/main/java/io/onedev/server/model/Project.java:1033

		ObjectId revId = getObjectId(revision, mustExist);
		if (revId != null) {
			return getRevCommit(revId, mustExist);
		} else {
			return null;
		}
	}
	
	@Nullable
	public RevCommit getRevCommit(ObjectId revId, boolean mustExist) {
		if (commitCache == null)
			commitCache = new HashMap<>();
		Optional<RevCommit> commit = commitCache.get(revId);
		if (commit == null) {
			commit = Optional.fromNullable(getGitService().getCommit(this, revId));
			commitCache.put(revId, commit);
		}
		if (mustExist && !commit.isPresent())
			throw new NotFoundException("Unable to find commit associated with object id: " + revId);
		else
			return commit.orNull();
	}
	
	public Collection<CodeComment> getCodeComments() {
		return codeComments;
	}

	public void setCodeComments(Collection<CodeComment> codeComments) {
		this.codeComments = codeComments;
	}
	
	@Editable(order=250, description="Whether or not to enable code management for the project")
	public boolean isCodeManagement() {
		return codeManagement;
	}

	public void setCodeManagement(boolean codeManagement) {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Resolve commit ids freshly via project.getCommitId(revision, false) instead of caching object ids across history changes.
  2. Verify the SHA exists with git cat-file -t <sha> in the repo (should print 'commit').
  3. Catch NotFoundException and re-resolve from a branch/tag before retrying.
  4. Ensure ids come from the same repository — cross-repo SHAs will not resolve.

Example fix

// before
RevCommit c = project.getCommit(revId, true); // stale revId after force-push
// after
RevCommit c;
try { c = project.getCommit(revId, true); }
catch (NotFoundException e) { revId = project.getCommitId(project.getDefaultBranch(), false); c = project.getCommit(revId, true); }
Defensive patterns

Strategy: try-catch

Validate before calling

ObjectId fresh = project.getCommitId(revision, false);
RevCommit c = (fresh != null) ? project.getCommit(fresh, false) : null;
if (c == null) { /* handle missing commit */ }

Try / catch

try { RevCommit c = project.getCommit(revId, true); } catch (NotFoundException e) { // re-resolve revId from a branch/tag before retrying }

Prevention

When it happens

Trigger: project.getCommit(objectId, true) where the ObjectId is not present in the repo (e.g. object garbage-collected, SHA from a different repo, or a non-commit object id such as a tree/blob).

Common situations: Referencing commit SHAs after a history rewrite/force-push removed them (or after GC pruned unreachable objects); copying SHAs between forks/repositories; passing a blob/tree object id where a commit is expected; cached ids surviving repository re-import.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/e8ad41dd41eef587. Report an issue: GitHub.