You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CorruptObjectException.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2008, 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. package org.eclipse.jgit.errors;
  14. import java.io.IOException;
  15. import java.text.MessageFormat;
  16. import org.eclipse.jgit.annotations.Nullable;
  17. import org.eclipse.jgit.internal.JGitText;
  18. import org.eclipse.jgit.lib.AnyObjectId;
  19. import org.eclipse.jgit.lib.ObjectChecker;
  20. import org.eclipse.jgit.lib.ObjectId;
  21. /**
  22. * Exception thrown when an object cannot be read from Git.
  23. */
  24. public class CorruptObjectException extends IOException {
  25. private static final long serialVersionUID = 1L;
  26. private ObjectChecker.ErrorType errorType;
  27. /**
  28. * Report a specific error condition discovered in an object.
  29. *
  30. * @param type
  31. * type of error
  32. * @param id
  33. * identity of the bad object
  34. * @param why
  35. * description of the error.
  36. * @since 4.2
  37. */
  38. public CorruptObjectException(ObjectChecker.ErrorType type, AnyObjectId id,
  39. String why) {
  40. super(MessageFormat.format(JGitText.get().objectIsCorrupt3,
  41. type.getMessageId(), id.name(), why));
  42. this.errorType = type;
  43. }
  44. /**
  45. * Construct a CorruptObjectException for reporting a problem specified
  46. * object id
  47. *
  48. * @param id
  49. * a {@link org.eclipse.jgit.lib.AnyObjectId}
  50. * @param why
  51. * error message
  52. */
  53. public CorruptObjectException(AnyObjectId id, String why) {
  54. super(MessageFormat.format(JGitText.get().objectIsCorrupt, id.name(), why));
  55. }
  56. /**
  57. * Construct a CorruptObjectException for reporting a problem specified
  58. * object id
  59. *
  60. * @param id
  61. * a {@link org.eclipse.jgit.lib.ObjectId}
  62. * @param why
  63. * error message
  64. */
  65. public CorruptObjectException(ObjectId id, String why) {
  66. super(MessageFormat.format(JGitText.get().objectIsCorrupt, id.name(), why));
  67. }
  68. /**
  69. * Construct a CorruptObjectException for reporting a problem not associated
  70. * with a specific object id.
  71. *
  72. * @param why
  73. * error message
  74. */
  75. public CorruptObjectException(String why) {
  76. super(why);
  77. }
  78. /**
  79. * Construct a CorruptObjectException for reporting a problem not associated
  80. * with a specific object id.
  81. *
  82. * @param why
  83. * message describing the corruption.
  84. * @param cause
  85. * optional root cause exception
  86. * @since 3.4
  87. */
  88. public CorruptObjectException(String why, Throwable cause) {
  89. super(why);
  90. initCause(cause);
  91. }
  92. /**
  93. * Specific error condition identified by
  94. * {@link org.eclipse.jgit.lib.ObjectChecker}.
  95. *
  96. * @return error condition or null.
  97. * @since 4.2
  98. */
  99. @Nullable
  100. public ObjectChecker.ErrorType getErrorType() {
  101. return errorType;
  102. }
  103. }