theonedev/onedev · error · NotFoundException

Unable to find blob path '' in revision ''

Error message

Unable to find blob path '' in revision ''

What it means

GitUtils.getInputStream opens a blob stream at a given path in a revision. It uses TreeWalk.forPath to locate the path inside the commit's tree; when the path does not exist in that revision it throws NotFoundException with a message embedding the path and revision. This is a lookup failure on repository content, not an I/O error.

Source

Thrown at server-core/src/main/java/io/onedev/server/git/GitUtils.java:242

		return diffs;
	}

	static void configureDiffFormatter(DiffFormatter diffFormatter, Repository repository) {
		diffFormatter.setRepository(repository);
		diffFormatter.setDetectRenames(true);
		diffFormatter.getRenameDetector().setRenameLimit(-1);
		diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
	}

	public static InputStream getInputStream(Repository repository, ObjectId revId, String path) {
		try (RevWalk revWalk = new RevWalk(repository)) {
			RevTree revTree = revWalk.parseCommit(revId).getTree();
			TreeWalk treeWalk = TreeWalk.forPath(repository, path, revTree);
			if (treeWalk != null) {
				ObjectLoader objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));
				return objectLoader.openStream();
			} else {
				throw new NotFoundException("Unable to find blob path '" + path + "' in revision '" + revId + "'");
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static Collection<String> getBlobPaths(Repository repository, ObjectId commitId) {
		Collection<String> blobPaths = new HashSet<>();
		try (RevWalk revWalk = new RevWalk(repository);
			 TreeWalk treeWalk = new TreeWalk(repository)) {
			RevCommit commit = revWalk.parseCommit(commitId);
			treeWalk.addTree(commit.getTree());
			treeWalk.setRecursive(true);
			treeWalk.setFilter(TreeFilter.ANY_DIFF);
			
			while (treeWalk.next()) {
				blobPaths.add(treeWalk.getPathString());
			}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the file exists at that revision: git cat-file -e <revId>:<path>
  2. Check the exact path including case and directory prefix at that commit (git ls-tree -r <revId>)
  3. Resolve the correct revision (the commit where the file exists) before calling
  4. If the path may be missing, pre-check with TreeWalk.forPath yourself or handle NotFoundException

Example fix

// before
try (InputStream is = GitUtils.getInputStream(repo, revId, "src/App.java")) { ... }

// after
TreeWalk tw = TreeWalk.forPath(repo, "src/App.java", revWalk.parseCommit(revId).getTree());
if (tw != null) {
    try (InputStream is = GitUtils.getInputStream(repo, revId, "src/App.java")) { ... }
} else {
    LOG.warn("Path src/App.java missing at " + revId.getName());
}
Defensive patterns

Strategy: try-catch

Validate before calling

TreeWalk tw = TreeWalk.forPath(repository, path, new RevWalk(repository).parseCommit(revId).getTree());
boolean exists = (tw != null);

Try / catch

try (InputStream is = GitUtils.getInputStream(repo, revId, path)) {
  // consume stream
} catch (NotFoundException e) {
  LOG.warn("Blob " + path + " not present at " + revId.getName());
  renderPlaceholder();
}

Prevention

When it happens

Trigger: Calling getInputStream(repository, revId, path) where TreeWalk.forPath(repository, path, revTree) returns null: path absent at that revision, path refers to a directory, wrong case, or the revision predates/postdates the file.

Common situations: Rendering a file from an old commit after it was renamed/deleted; deep-linking to a blob at a branch that moved; path separator or case mismatch; passing a commit id that is not the one containing the file.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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