theonedev/onedev · error · IllegalArgumentException

Bad object type {0}

Error message

Bad object type {0}

What it means

RevWalk.parseAny/parseCommit-style entry points inspect the object type stored in the repository (commit, tree, blob, tag). When the object database returns a type constant outside the known set (0 or >4), the walk cannot build a RevObject for it and throws this IllegalArgumentException. This normally indicates a corrupt or non-standard object in the repository.

Source

Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java:1219

		}
		case Constants.OBJ_TREE: {
			r = new RevTree(id);
			r.flags |= PARSED;
			break;
		}
		case Constants.OBJ_BLOB: {
			r = new RevBlob(id);
			r.flags |= PARSED;
			break;
		}
		case Constants.OBJ_TAG: {
			final RevTag t = new RevTag(id);
			t.parseCanonical(this, getCachedBytes(t, ldr));
			r = t;
			break;
		}
		default:
			throw new IllegalArgumentException(MessageFormat.format(
					JGitText.get().badObjectType, Integer.valueOf(type)));
		}
		objects.add(r);
		return r;
	}

	byte[] getCachedBytes(RevObject obj) throws LargeObjectException,
			MissingObjectException, IncorrectObjectTypeException, IOException {
		return getCachedBytes(obj, reader.open(obj, obj.getType()));
	}

	byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)
			throws LargeObjectException, MissingObjectException, IOException {
		try {
			return ldr.getCachedBytes(5 * MB);
		} catch (LargeObjectException tooBig) {
			tooBig.setObjectId(obj);
			throw tooBig;

View on GitHub (pinned to d44925c47c)

Solutions

  1. Run 'git fsck --full' on the repository to locate and assess corrupt objects.
  2. Restore the repository from backup or re-clone from a healthy remote.
  3. Identify the offending object id from the message/context and repair or remove it.
  4. If caused by a third-party writer, stop using that writer or upgrade JGit to one supporting the object type.
Defensive patterns

Strategy: try-catch

Validate before calling

// detect corruption ahead of parsing
Status s = Git.open(repoDir).getRepository().fsck(); // or run `git fsck --full` via CLI

Type guard

Integer type = repo.open(id).getType();
boolean known = type >= Constants.OBJ_COMMIT && type <= Constants.OBJ_TAG; // 1..4

Try / catch

try {
    return walk.parseAny(id);
} catch (IllegalArgumentException e) {
    throw new RepositoryCorruptedException("Unrecognized object type for " + id, e);
}

Prevention

When it happens

Trigger: Parsing an object id whose backing storage reports an unrecognized type constant, e.g. a corrupted loose object header, an object type added by a newer/exotic git implementation, or a pack containing malformed type bits.

Common situations: Repository corruption after disk failure or interrupted gc; reading repositories produced by tools that write non-standard object types; tests feeding fabricated ObjectIds into RevWalk.parseAny.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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