From 8924d4e0a09ea792123a892ba2b7d2c0bfd11946 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Thu, 3 Apr 2014 10:10:01 -0700 Subject: [PATCH] Throw CorruptObjectException when a bad object is found This makes it easier to identify higher in the call stack. Change-Id: I829431c38c71fa1899e33916252b75f09db8ecbd --- .../jgit/errors/CorruptObjectException.java | 15 +++++++++++++++ .../org/eclipse/jgit/transport/PackParser.java | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CorruptObjectException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CorruptObjectException.java index 610423353..c6ea09375 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CorruptObjectException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CorruptObjectException.java @@ -90,4 +90,19 @@ public class CorruptObjectException extends IOException { public CorruptObjectException(final String why) { super(why); } + + /** + * Construct a CorruptObjectException for reporting a problem not associated + * with a specific object id. + * + * @param why + * message describing the corruption. + * @param cause + * optional root cause exception + * @since 3.4 + */ + public CorruptObjectException(String why, Throwable cause) { + super(why); + initCause(cause); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java index 93522c1e9..4f53d2267 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java @@ -1014,9 +1014,10 @@ public abstract class PackParser { try { objCheck.check(type, data); } catch (CorruptObjectException e) { - throw new IOException(MessageFormat.format( - JGitText.get().invalidObject, Constants - .typeString(type), id.name(), e.getMessage())); + throw new CorruptObjectException(MessageFormat.format( + JGitText.get().invalidObject, + Constants.typeString(type), + id.name(), e.getMessage()), e); } }