Browse Source

Throw IncorrectObjectTypeException on bad type hints

If the type hint isn't OBJ_ANY and it doesn't match the actual type
observed from the object store, define the reader to throw back an
IncorrectObjectTypeException.  This way the caller doesn't have to
perform this check itself before it evaluates the object data, and
we can simplify quite a few call sites.

Change-Id: I9f0dfa033857f439c94245361fcae515bc0a6533
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
9ba7bd4df4
  1. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
  2. 6
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java

6
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java

@ -45,6 +45,7 @@ package org.eclipse.jgit.lib;
import java.io.IOException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.storage.pack.ObjectReuseAsIs;
@ -103,10 +104,13 @@ public abstract class ObjectReader {
* @return a {@link ObjectLoader} for accessing the object.
* @throws MissingObjectException
* the object does not exist.
* @throws IncorrectObjectTypeException
* typeHint was not OBJ_ANY, and the object's actual type does
* not match typeHint.
* @throws IOException
*/
public abstract ObjectLoader openObject(AnyObjectId objectId, int typeHint)
throws MissingObjectException, IOException;
throws MissingObjectException, IncorrectObjectTypeException, IOException;
/**
* Release any resources used by this reader.

6
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java

@ -48,6 +48,7 @@ import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.lib.AnyObjectId;
@ -81,13 +82,16 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
}
public ObjectLoader openObject(AnyObjectId objectId, int typeHint)
throws MissingObjectException, IOException {
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
final ObjectLoader ldr = db.openObject(this, objectId);
if (ldr == null) {
if (typeHint == OBJ_ANY)
throw new MissingObjectException(objectId.copy(), "unknown");
throw new MissingObjectException(objectId.copy(), typeHint);
}
if (typeHint != OBJ_ANY && ldr.getType() != typeHint)
throw new IncorrectObjectTypeException(objectId.copy(), typeHint);
return ldr;
}

Loading…
Cancel
Save