1 /* 2 * Copyright (C) 2009, Google Inc. 3 * Copyright (C) 2008, Jonas Fonseca <fonseca@diku.dk> 4 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com> 5 * Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org> and others 6 * 7 * This program and the accompanying materials are made available under the 8 * terms of the Eclipse Distribution License v. 1.0 which is available at 9 * https://www.eclipse.org/org/documents/edl-v10.php. 10 * 11 * SPDX-License-Identifier: BSD-3-Clause 12 */ 13 14 package org.eclipse.jgit.errors; 15 16 import java.io.IOException; 17 import java.text.MessageFormat; 18 19 import org.eclipse.jgit.internal.JGitText; 20 import org.eclipse.jgit.lib.AbbreviatedObjectId; 21 import org.eclipse.jgit.lib.Constants; 22 import org.eclipse.jgit.lib.ObjectId; 23 24 /** 25 * An expected object is missing. 26 */ 27 public class MissingObjectException extends IOException { 28 private static final long serialVersionUID = 1L; 29 30 private final ObjectId missing; 31 32 /** 33 * Construct a MissingObjectException for the specified object id. 34 * Expected type is reported to simplify tracking down the problem. 35 * 36 * @param id SHA-1 37 * @param type object type 38 */ 39 public MissingObjectException(ObjectId id, String type) { 40 super(MessageFormat.format(JGitText.get().missingObject, type, id.name())); 41 missing = id.copy(); 42 } 43 44 /** 45 * Construct a MissingObjectException for the specified object id. 46 * Expected type is reported to simplify tracking down the problem. 47 * 48 * @param id SHA-1 49 * @param type object type 50 */ 51 public MissingObjectException(ObjectId id, int type) { 52 this(id, Constants.typeString(type)); 53 } 54 55 /** 56 * Construct a MissingObjectException for the specified object id. Expected 57 * type is reported to simplify tracking down the problem. 58 * 59 * @param id 60 * SHA-1 61 * @param type 62 * object type 63 */ 64 public MissingObjectException(AbbreviatedObjectId id, int type) { 65 super(MessageFormat.format(JGitText.get().missingObject, Constants 66 .typeString(type), id.name())); 67 missing = null; 68 } 69 70 /** 71 * Get the ObjectId that was not found 72 * 73 * @return the ObjectId that was not found 74 */ 75 public ObjectId getObjectId() { 76 return missing; 77 } 78 }