aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-08-30 11:53:25 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-08-30 11:53:25 -0700
commite6bd689d2c48efb4e6662ffca2fbdbc7570d2db1 (patch)
tree0b19b3c1a845a0626c61ba1c7954cfd2f8844834 /org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java
parenta3945d1bc856322becdc4d1ec8df9013bfef3175 (diff)
downloadjgit-e6bd689d2c48efb4e6662ffca2fbdbc7570d2db1.tar.gz
jgit-e6bd689d2c48efb4e6662ffca2fbdbc7570d2db1.zip
Improve LargeObjectException reporting
Use 3 different types of LargeObjectException for the 3 major ways that we can fail to load an object. For each of these use a unique string translation which describes the root cause better than just the ObjectId.name() does. Change-Id: I810c98d5691b74af9fc6cbd46fc9879e35a7bdca Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java74
1 files changed, 73 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java
index f77aecbb42..a1107dc35f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/LargeObjectException.java
@@ -43,6 +43,9 @@
package org.eclipse.jgit.errors;
+import java.text.MessageFormat;
+
+import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
@@ -73,6 +76,13 @@ public class LargeObjectException extends RuntimeException {
return objectId;
}
+ /** @return either the hex encoded name of the object, or 'unknown object'. */
+ protected String getObjectName() {
+ if (getObjectId() != null)
+ return getObjectId().name();
+ return JGitText.get().unknownObject;
+ }
+
/**
* Set the identity of the object, if its not already set.
*
@@ -86,6 +96,68 @@ public class LargeObjectException extends RuntimeException {
@Override
public String getMessage() {
- return objectId != null ? objectId.name() : getClass().getSimpleName();
+ return MessageFormat.format(JGitText.get().largeObjectException,
+ getObjectName());
+ }
+
+ /** An error caused by the JVM being out of heap space. */
+ public static class OutOfMemory extends LargeObjectException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct a wrapper around the original OutOfMemoryError.
+ *
+ * @param cause
+ * the original root cause.
+ */
+ public OutOfMemory(OutOfMemoryError cause) {
+ initCause(cause);
+ }
+
+ @Override
+ public String getMessage() {
+ return MessageFormat.format(JGitText.get().largeObjectOutOfMemory,
+ getObjectName());
+ }
+ }
+
+ /** Object size exceeds JVM limit of 2 GiB per byte array. */
+ public static class ExceedsByteArrayLimit extends LargeObjectException {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getMessage() {
+ return MessageFormat
+ .format(JGitText.get().largeObjectExceedsByteArray,
+ getObjectName());
+ }
+ }
+
+ /** Object size exceeds the caller's upper limit. */
+ public static class ExceedsLimit extends LargeObjectException {
+ private static final long serialVersionUID = 1L;
+
+ private final long limit;
+
+ private final long size;
+
+ /**
+ * Construct an exception for a particular size being exceeded.
+ *
+ * @param limit
+ * the limit the caller imposed on the object.
+ * @param size
+ * the actual size of the object.
+ */
+ public ExceedsLimit(long limit, long size) {
+ this.limit = limit;
+ this.size = size;
+ }
+
+ @Override
+ public String getMessage() {
+ return MessageFormat.format(JGitText.get().largeObjectExceedsLimit,
+ getObjectName(), limit, size);
+ }
}
}