Browse Source

Add ObjectId to the LargeObjectException

A chunk of code that throws LargeObjectException may or may not have
the specific ObjectId on hand when its thrown.  If it does, we want
to cache it in the exception, and put that in the message.  If it is
missing we want to be able to set it later from a higher level stack
frame that does have the object handy.

Change-Id: Ife25546158868bdfa886037e4493ef8235ebe4b9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
tags/v0.9.1
Shawn O. Pearce 13 years ago
parent
commit
1f4b48a37c

+ 26
- 2
org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java View File

@@ -43,12 +43,15 @@

package org.eclipse.jgit.errors;

import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;

/** An object is too big to load into memory as a single byte array. */
public class LargeObjectException extends RuntimeException {
private static final long serialVersionUID = 1L;

private ObjectId objectId;

/** Create a large object exception, where the object isn't known. */
public LargeObjectException() {
// Do nothing.
@@ -61,7 +64,28 @@ public class LargeObjectException extends RuntimeException {
* identity of the object that is too big to be loaded as a byte
* array in this JVM.
*/
public LargeObjectException(ObjectId id) {
super(id.name());
public LargeObjectException(AnyObjectId id) {
setObjectId(id);
}

/** @return identity of the object that is too large; may be null. */
public ObjectId getObjectId() {
return objectId;
}

/**
* Set the identity of the object, if its not already set.
*
* @param id
* the id of the object that is too large to process.
*/
public void setObjectId(AnyObjectId id) {
if (objectId == null)
objectId = id.copy();
}

@Override
public String getMessage() {
return objectId != null ? objectId.name() : getClass().getSimpleName();
}
}

Loading…
Cancel
Save