From ebe9b3bdcf872d6e1776745fa9bec95be8dbc6eb Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 12 Jun 2009 16:00:16 -0700 Subject: [PATCH] Allow exceptions to be created with integer type codes This may be easier in some contexts where we have the type code we expect handy, but not the type string constant. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../spearce/jgit/errors/IncorrectObjectTypeException.java | 13 +++++++++++++ .../src/org/spearce/jgit/errors/MissingObjectException.java | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java index a194f196..3af1f44d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java +++ b/org.spearce.jgit/src/org/spearce/jgit/errors/IncorrectObjectTypeException.java @@ -40,6 +40,7 @@ package org.spearce.jgit.errors; import java.io.IOException; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.ObjectId; /** @@ -62,4 +63,16 @@ public class IncorrectObjectTypeException extends IOException { public IncorrectObjectTypeException(final ObjectId id, final String type) { super("Object " + id.name() + " is not a " + type + "."); } + + /** + * Construct and IncorrectObjectTypeException for the specified object id. + * + * Provide the type to make it easier to track down the problem. + * + * @param id SHA-1 + * @param type object type + */ + public IncorrectObjectTypeException(final ObjectId id, final int type) { + this(id, Constants.typeString(type)); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java index 37147c30..7b7b8f37 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java +++ b/org.spearce.jgit/src/org/spearce/jgit/errors/MissingObjectException.java @@ -40,6 +40,7 @@ package org.spearce.jgit.errors; import java.io.IOException; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.ObjectId; /** @@ -58,4 +59,15 @@ public class MissingObjectException extends IOException { public MissingObjectException(final ObjectId id, final String type) { super("Missing " + type + " " + id.name()); } + + /** + * Construct a MissingObjectException for the specified object id. + * Expected type is reported to simplify tracking down the problem. + * + * @param id SHA-1 + * @param type object type + */ + public MissingObjectException(final ObjectId id, final int type) { + this(id, Constants.typeString(type)); + } } -- 2.11.4.GIT