Browse Source

ErrorProne: Enable and fix UnusedException check

Enable UnusedException at ERROR level which causes the build to fail
in many places with:

  [UnusedException] This catch block catches an symbol and re-throws
  another, but swallows the caught symbol rather than setting it as a
  cause. This can make debugging harder.

Fix it by setting the caught exception as cause on the subsequently
thrown exception.

Note: The grammatically incorrect error message is copy-pasted as-is
from the version of ErrorProne currently used in Bazel; it has been
fixed by [1] in the latest version.

[1] https://github.com/google/error-prone/commit/d57a39c

Change-Id: I11ed38243091fc12f64f1b2db404ba3f1d2e98b5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.8
David Pursehouse 4 years ago committed by Matthias Sohn
parent
commit
4cc13297cc
  1. 3
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java
  2. 2
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  3. 2
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
  4. 7
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java
  5. 8
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java
  6. 8
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java
  7. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
  8. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  9. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java
  10. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
  11. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java
  12. 8
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  13. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
  14. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java
  15. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java
  16. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java
  17. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java
  18. 7
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
  19. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java
  20. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
  21. 5
      org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
  22. 1
      org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
  23. 2
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
  24. 2
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
  25. 7
      org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java
  26. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java
  27. 3
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
  28. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
  29. 5
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  30. 16
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java
  31. 9
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
  32. 7
      org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java
  33. 7
      org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java
  34. 5
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
  35. 10
      org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
  36. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java
  37. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java
  38. 20
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  39. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
  40. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java
  41. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
  42. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
  43. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java
  44. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java
  45. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
  46. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
  47. 13
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java
  48. 2
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
  49. 3
      org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
  50. 15
      org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java
  51. 17
      org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java
  52. 1
      tools/BUILD

3
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java

@ -298,7 +298,8 @@ public class GitFilter extends MetaFilter {
try {
return StringUtils.toBoolean(n);
} catch (IllegalArgumentException err) {
throw new ServletException(MessageFormat.format(HttpServerText.get().invalidBoolean, param, n));
throw new ServletException(MessageFormat.format(
HttpServerText.get().invalidBoolean, param, n), err);
}
}

2
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -973,7 +973,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
try {
lck.write(bin);
} catch (IOException ioe) {
throw new ObjectWritingException("Can't write " + p);
throw new ObjectWritingException("Can't write " + p, ioe);
}
if (!lck.commit())
throw new ObjectWritingException("Can't write " + p);

2
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java

@ -18,7 +18,6 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale;
import org.eclipse.jgit.annotations.Nullable;
@ -110,7 +109,6 @@ public class LfsPointer implements Comparable<LfsPointer> {
ps.print(size + "\n"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
// should not happen, we are using a standard charset
throw new UnsupportedCharsetException(UTF_8.name());
}
}

7
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java

@ -121,8 +121,11 @@ public final class AbbreviatedLongObjectId implements Serializable {
final long c = hexUInt64(bs, ptr + 32, end);
final long d = hexUInt64(bs, ptr + 48, end);
return new AbbreviatedLongObjectId(end - ptr, a, b, c, d);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidLongObjectIdException(bs, ptr, end - ptr);
} catch (ArrayIndexOutOfBoundsException e) {
InvalidLongObjectIdException e1 = new InvalidLongObjectIdException(
bs, ptr, end - ptr);
e1.initCause(e);
throw e1;
}
}

8
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java

@ -223,9 +223,11 @@ public class LongObjectId extends AnyLongObjectId implements Serializable {
final long c = RawParseUtils.parseHexInt64(bs, p + 32);
final long d = RawParseUtils.parseHexInt64(bs, p + 48);
return new LongObjectId(a, b, c, d);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidLongObjectIdException(bs, p,
Constants.LONG_OBJECT_ID_STRING_LENGTH);
} catch (ArrayIndexOutOfBoundsException e) {
InvalidLongObjectIdException e1 = new InvalidLongObjectIdException(
bs, p, Constants.LONG_OBJECT_ID_STRING_LENGTH);
e1.initCause(e);
throw e1;
}
}

8
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java

@ -213,9 +213,11 @@ public class MutableLongObjectId extends AnyLongObjectId {
w2 = RawParseUtils.parseHexInt64(bs, p + 16);
w3 = RawParseUtils.parseHexInt64(bs, p + 32);
w4 = RawParseUtils.parseHexInt64(bs, p + 48);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidLongObjectIdException(bs, p,
Constants.LONG_OBJECT_ID_STRING_LENGTH);
} catch (ArrayIndexOutOfBoundsException e) {
InvalidLongObjectIdException e1 = new InvalidLongObjectIdException(
bs, p, Constants.LONG_OBJECT_ID_STRING_LENGTH);
e1.initCause(e);
throw e1;
}
}

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java

@ -100,7 +100,7 @@ class Checkout extends TextBuiltin {
.format(CLIText.get().pathspecDidNotMatch, name), e);
} catch (RefAlreadyExistsException e) {
throw die(MessageFormat
.format(CLIText.get().branchAlreadyExists, name));
.format(CLIText.get().branchAlreadyExists, name), e);
} catch (CheckoutConflictException e) {
StringBuilder builder = new StringBuilder();
builder.append(CLIText.get().checkoutConflict);

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -110,7 +110,7 @@ class Clone extends AbstractFetchCommand implements CloneCommand.Callback {
outw.println(CLIText.get().clonedEmptyRepository);
} catch (InvalidRemoteException e) {
throw die(MessageFormat.format(CLIText.get().doesNotExist,
sourceUri));
sourceUri), e);
} finally {
if (db != null)
db.close();

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java

@ -42,7 +42,7 @@ class ReceivePack extends TextBuiltin {
db = key.open(true /* must exist */);
} catch (RepositoryNotFoundException notFound) {
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
dstGitdir.getPath()));
dstGitdir.getPath()), notFound);
} catch (IOException e) {
throw die(e.getMessage(), e);
}

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java

@ -74,7 +74,7 @@ class Tag extends TextBuiltin {
command.call();
} catch (RefAlreadyExistsException e) {
throw die(MessageFormat.format(
CLIText.get().tagAlreadyExists, tagName));
CLIText.get().tagAlreadyExists, tagName), e);
}
}
} else {

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java

@ -50,7 +50,7 @@ class UploadPack extends TextBuiltin {
up.upload(ins, outs, errs);
} catch (RepositoryNotFoundException notFound) {
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
srcGitdir.getPath()));
srcGitdir.getPath()), notFound);
} catch (IOException e) {
throw die(e.getMessage(), e);
}

8
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -235,7 +235,9 @@ class RebuildCommitGraph extends TextBuiltin {
try {
lck.write(content);
} catch (IOException ioe) {
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
throw new ObjectWritingException(
MessageFormat.format(CLIText.get().cantWrite, file),
ioe);
}
if (!lck.commit())
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
@ -266,7 +268,9 @@ class RebuildCommitGraph extends TextBuiltin {
errw.println(MessageFormat.format(CLIText.get().skippingObject, type, name));
continue;
}
throw new MissingObjectException(id, type);
MissingObjectException mue1 = new MissingObjectException(id, type);
mue1.initCause(mue);
throw mue1;
}
refs.put(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED,
name, id));

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java

@ -57,7 +57,7 @@ class ShowPackDelta extends TextBuiltin {
if (BinaryDelta.getResultSize(delta) != size)
throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (ArrayIndexOutOfBoundsException bad) {
throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$
throw die("Object " + obj.name() + " is not a delta", bad); //$NON-NLS-1$ //$NON-NLS-2$
}
outw.println(BinaryDelta.format(delta));

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java

@ -101,8 +101,10 @@ public class AbstractTreeIteratorHandler extends
try (ObjectReader curs = clp.getRepository().newObjectReader()) {
p.reset(curs, clp.getRevWalk().parseTree(id));
} catch (MissingObjectException | IncorrectObjectTypeException e) {
throw new CmdLineException(clp,
CmdLineException cle = new CmdLineException(clp,
CLIText.format(CLIText.get().notATree), name);
cle.initCause(e);
throw cle;
} catch (IOException e) {
throw new CmdLineException(clp,
CLIText.format(CLIText.get().cannotReadBecause), name,

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java

@ -98,8 +98,10 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
try {
c = clp.getRevWalk().parseCommit(id);
} catch (MissingObjectException | IncorrectObjectTypeException e) {
throw new CmdLineException(clp,
CmdLineException cle = new CmdLineException(clp,
CLIText.format(CLIText.get().notACommit), name);
cle.initCause(e);
throw cle;
} catch (IOException e) {
throw new CmdLineException(clp,
CLIText.format(CLIText.get().cannotReadBecause), name,

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java

@ -70,8 +70,10 @@ public class RevTreeHandler extends OptionHandler<RevTree> {
try {
c = clp.getRevWalk().parseTree(id);
} catch (MissingObjectException | IncorrectObjectTypeException e) {
throw new CmdLineException(clp,
CmdLineException cle = new CmdLineException(clp,
CLIText.format(CLIText.get().notATree), name);
cle.initCause(e);
throw cle;
} catch (IOException e) {
throw new CmdLineException(clp,
CLIText.format(CLIText.get().cannotReadBecause), name,

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java

@ -149,7 +149,9 @@ public class TimeoutOutputStreamTest {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new InterruptedIOException();
InterruptedIOException e1 = new InterruptedIOException();
e1.initCause(e);
throw e1;
}
}
}
@ -202,7 +204,9 @@ public class TimeoutOutputStreamTest {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new InterruptedIOException();
InterruptedIOException e1 = new InterruptedIOException();
e1.initCause(e);
throw e1;
}
}
}

7
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

@ -160,7 +160,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
verifyDirectories(u);
} catch (URISyntaxException e) {
throw new InvalidRemoteException(
MessageFormat.format(JGitText.get().invalidURL, uri));
MessageFormat.format(JGitText.get().invalidURL, uri), e);
}
@SuppressWarnings("resource") // Closed by caller
Repository repository = init();
@ -180,8 +180,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
repository.close();
}
cleanup();
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
throw new InvalidRemoteException(
MessageFormat.format(JGitText.get().invalidRemote, remote),
e);
} catch (GitAPIException | RuntimeException e) {
if (repository != null) {
repository.close();

2
org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java

@ -223,7 +223,7 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> {
e.getMessage(), e);
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
JGitText.get().invalidRemote, remote), e);
} catch (NotSupportedException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand,

2
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java

@ -180,7 +180,7 @@ public class LsRemoteCommand extends
}
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
JGitText.get().invalidRemote, remote), e);
} catch (NotSupportedException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,

5
org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java

@ -152,8 +152,9 @@ public class PushCommand extends
}
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
throw new InvalidRemoteException(
MessageFormat.format(JGitText.get().invalidRemote, remote),
e);
} catch (TransportException e) {
throw new org.eclipse.jgit.api.errors.TransportException(
e.getMessage(), e);

1
org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java

@ -350,6 +350,7 @@ public class SimilarityIndex {
return (1 << idHashBits) * (idHashBits - 3) / idHashBits;
}
@SuppressWarnings("UnusedException")
private void grow() throws TableFullException {
if (idHashBits == 30)
throw new TableFullException();

2
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

@ -139,7 +139,7 @@ public class ManifestParser extends DefaultHandler {
try {
xr = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
throw new IOException(JGitText.get().noXMLParserAvailable);
throw new IOException(JGitText.get().noXMLParserAvailable, e);
}
xr.setContentHandler(this);
try {

2
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java

@ -541,7 +541,7 @@ public class RepoCommand extends GitCommand<RevCommit> {
inputStream = new FileInputStream(manifestPath);
} catch (IOException e) {
throw new IllegalArgumentException(
JGitText.get().pathNotConfigured);
JGitText.get().pathNotConfigured, e);
}
}

7
org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java

@ -290,9 +290,12 @@ public class FsckPackParser extends PackParser {
ErrorType.MISMATCH_CRC);
}
} catch (MissingObjectException e) {
throw new CorruptPackIndexException(MessageFormat
.format(JGitText.get().missingCRC, entry.getName()),
CorruptPackIndexException cpe = new CorruptPackIndexException(
MessageFormat.format(JGitText.get().missingCRC,
entry.getName()),
ErrorType.MISSING_CRC);
cpe.initCause(e);
throw cpe;
}
}

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java

@ -236,7 +236,7 @@ public class DfsBlockCacheConfig {
JGitText.get().enumValueNotSupported3,
CONFIG_CORE_SECTION,
CONFIG_DFS_SECTION,
CONFIG_KEY_STREAM_RATIO, v));
CONFIG_KEY_STREAM_RATIO, v), e);
}
}
return this;

3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java

@ -769,7 +769,8 @@ public class ObjectDirectory extends FileObjectDatabase {
shallowCommitsIds.add(ObjectId.fromString(line));
} catch (IllegalArgumentException ex) {
throw new IOException(MessageFormat
.format(JGitText.get().badShallowLine, line));
.format(JGitText.get().badShallowLine, line),
ex);
}
}
}

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

@ -1071,7 +1071,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
} catch (DataFormatException e) {
throw new CorruptObjectException(MessageFormat.format(
JGitText.get().objectAtHasBadZlibStream, Long.valueOf(pos),
getPackFile()));
getPackFile()), e);
}
}

5
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -1035,7 +1035,10 @@ public class RefDirectory extends RefDatabase {
lck.waitForStatChange();
} catch (InterruptedException e) {
lck.unlock();
throw new ObjectWritingException(MessageFormat.format(JGitText.get().interruptedWriting, name));
throw new ObjectWritingException(
MessageFormat.format(
JGitText.get().interruptedWriting, name),
e);
}
if (!lck.commit())
throw new ObjectWritingException(MessageFormat.format(JGitText.get().unableToWrite, name));

16
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java

@ -149,8 +149,10 @@ public class UnpackedObject {
}
return new LargeObject(type, size, path, id, wc.db);
} catch (ZipException badStream) {
throw new CorruptObjectException(id,
CorruptObjectException coe = new CorruptObjectException(id,
JGitText.get().corruptObjectBadStream);
coe.initCause(badStream);
throw coe;
}
}
@ -192,8 +194,10 @@ public class UnpackedObject {
}
return size;
} catch (ZipException badStream) {
throw new CorruptObjectException(id,
CorruptObjectException coe = new CorruptObjectException(id,
JGitText.get().corruptObjectBadStream);
coe.initCause(badStream);
throw coe;
}
}
@ -205,8 +209,10 @@ public class UnpackedObject {
try {
r = inf.inflate(buf);
} catch (DataFormatException e) {
throw new CorruptObjectException(id,
CorruptObjectException coe = new CorruptObjectException(id,
JGitText.get().corruptObjectBadStream);
coe.initCause(e);
throw coe;
}
if (r != 0)
throw new CorruptObjectException(id,
@ -277,8 +283,10 @@ public class UnpackedObject {
remaining -= r;
return r;
} catch (ZipException badStream) {
throw new CorruptObjectException(id,
CorruptObjectException coe = new CorruptObjectException(id,
JGitText.get().corruptObjectBadStream);
coe.initCause(badStream);
throw coe;
}
}

9
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

@ -1579,8 +1579,8 @@ public class PackWriter implements AutoCloseable {
if (pool.awaitTermination(60, TimeUnit.SECONDS))
break;
} catch (InterruptedException e) {
throw new IOException(
JGitText.get().packingCancelledDuringObjectsWriting);
throw new IOException(JGitText
.get().packingCancelledDuringObjectsWriting, e);
}
}
}
@ -1604,7 +1604,8 @@ public class PackWriter implements AutoCloseable {
// Cross our fingers and just break out anyway.
//
throw new IOException(
JGitText.get().packingCancelledDuringObjectsWriting);
JGitText.get().packingCancelledDuringObjectsWriting,
ie);
}
}
@ -1645,7 +1646,7 @@ public class PackWriter implements AutoCloseable {
for (Future<?> f : futures)
f.cancel(true);
throw new IOException(
JGitText.get().packingCancelledDuringObjectsWriting);
JGitText.get().packingCancelledDuringObjectsWriting, ie);
}
}

7
org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java

@ -165,9 +165,10 @@ public class SubmoduleValidator {
}
}
} catch (ConfigInvalidException e) {
throw new SubmoduleValidationException(
JGitText.get().invalidGitModules,
GITMODULES_PARSE);
SubmoduleValidationException sve = new SubmoduleValidationException(
JGitText.get().invalidGitModules, GITMODULES_PARSE);
sve.initCause(e);
throw sve;
}
}
}

7
org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java

@ -114,8 +114,11 @@ public final class AbbreviatedObjectId implements Serializable {
final int d = hexUInt32(bs, ptr + 24, end);
final int e = hexUInt32(bs, ptr + 32, end);
return new AbbreviatedObjectId(end - ptr, a, b, c, d, e);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidObjectIdException(bs, ptr, end - ptr);
} catch (ArrayIndexOutOfBoundsException e) {
InvalidObjectIdException e1 = new InvalidObjectIdException(bs, ptr,
end - ptr);
e1.initCause(e);
throw e1;
}
}

5
org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java

@ -601,7 +601,10 @@ public final class Constants {
throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
}
} catch (ArrayIndexOutOfBoundsException bad) {
throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType);
CorruptObjectException coe = new CorruptObjectException(id,
JGitText.get().corruptObjectInvalidType);
coe.initCause(bad);
throw coe;
}
}

10
org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java

@ -46,7 +46,7 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
return StringUtils.toBoolean(n);
} catch (IllegalArgumentException err) {
throw new IllegalArgumentException(MessageFormat.format(
JGitText.get().invalidBooleanValue, section, name, n));
JGitText.get().invalidBooleanValue, section, name, n), err);
}
}
@ -152,7 +152,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
return mul * Long.parseLong(n);
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException(MessageFormat.format(
JGitText.get().invalidIntegerValue, section, name, str));
JGitText.get().invalidIntegerValue, section, name, str),
nfe);
}
}
@ -239,7 +240,10 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
return wantUnit.convert(Long.parseLong(digits) * inputMul,
inputUnit);
} catch (NumberFormatException nfe) {
throw notTimeUnit(section, subsection, unitName, valueString);
IllegalArgumentException iae = notTimeUnit(section, subsection,
unitName, valueString);
iae.initCause(nfe);
throw iae;
}
}

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

@ -234,9 +234,11 @@ public class MutableObjectId extends AnyObjectId {
w3 = RawParseUtils.parseHexInt32(bs, p + 16);
w4 = RawParseUtils.parseHexInt32(bs, p + 24);
w5 = RawParseUtils.parseHexInt32(bs, p + 32);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidObjectIdException(bs, p,
} catch (ArrayIndexOutOfBoundsException e) {
InvalidObjectIdException e1 = new InvalidObjectIdException(bs, p,
Constants.OBJECT_ID_STRING_LENGTH);
e1.initCause(e);
throw e1;
}
}

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

@ -213,9 +213,11 @@ public class ObjectId extends AnyObjectId implements Serializable {
final int d = RawParseUtils.parseHexInt32(bs, p + 24);
final int e = RawParseUtils.parseHexInt32(bs, p + 32);
return new ObjectId(a, b, c, d, e);
} catch (ArrayIndexOutOfBoundsException e1) {
throw new InvalidObjectIdException(bs, p,
} catch (ArrayIndexOutOfBoundsException e) {
InvalidObjectIdException e1 = new InvalidObjectIdException(bs, p,
Constants.OBJECT_ID_STRING_LENGTH);
e1.initCause(e);
throw e1;
}
}

20
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -550,9 +550,11 @@ public abstract class Repository implements AutoCloseable {
try {
pnum = Integer.parseInt(parentnum);
} catch (NumberFormatException e) {
throw new RevisionSyntaxException(
RevisionSyntaxException rse = new RevisionSyntaxException(
JGitText.get().invalidCommitParentNumber,
revstr);
rse.initCause(e);
throw rse;
}
if (pnum != 0) {
RevCommit commit = (RevCommit) rev;
@ -647,8 +649,10 @@ public abstract class Repository implements AutoCloseable {
try {
dist = Integer.parseInt(distnum);
} catch (NumberFormatException e) {
throw new RevisionSyntaxException(
RevisionSyntaxException rse = new RevisionSyntaxException(
JGitText.get().invalidAncestryLength, revstr);
rse.initCause(e);
throw rse;
}
} else
dist = 1;
@ -707,7 +711,10 @@ public abstract class Repository implements AutoCloseable {
remoteConfig = new RemoteConfig(getConfig(),
"origin"); //$NON-NLS-1$
} catch (URISyntaxException e) {
throw new RevisionSyntaxException(revstr);
RevisionSyntaxException rse = new RevisionSyntaxException(
revstr);
rse.initCause(e);
throw rse;
}
String remoteBranchName = getConfig()
.getString(
@ -874,8 +881,11 @@ public abstract class Repository implements AutoCloseable {
try {
number = Integer.parseInt(time);
} catch (NumberFormatException nfe) {
throw new RevisionSyntaxException(MessageFormat.format(
JGitText.get().invalidReflogRevision, time));
RevisionSyntaxException rse = new RevisionSyntaxException(
MessageFormat.format(JGitText.get().invalidReflogRevision,
time));
rse.initCause(nfe);
throw rse;
}
assert number >= 0;
ReflogReader reader = getReflogReader(ref.getName());

3
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

@ -655,7 +655,8 @@ public class AmazonS3 {
try {
xr = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
throw new IOException(JGitText.get().noXMLParserAvailable);
throw new IOException(
JGitText.get().noXMLParserAvailable, e);
}
xr.setContentHandler(this);
try (InputStream in = c.getInputStream()) {

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java

@ -203,7 +203,9 @@ abstract class BasePackConnection extends BaseConnection {
try {
id = ObjectId.fromString(line.substring(0, 40));
} catch (InvalidObjectIdException e) {
throw invalidRefAdvertisementLine(line);
PackProtocolException ppe = invalidRefAdvertisementLine(line);
ppe.initCause(e);
throw ppe;
}
if (name.equals(".have")) { //$NON-NLS-1$
additionalHaves.add(id);

8
org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java

@ -286,7 +286,7 @@ public class PacketLineIn {
try {
len = RawParseUtils.parseHexInt16(lineBuffer, 0);
} catch (ArrayIndexOutOfBoundsException err) {
throw invalidHeader();
throw invalidHeader(err);
}
if (len == 0) {
@ -320,6 +320,12 @@ public class PacketLineIn {
+ (char) lineBuffer[2] + (char) lineBuffer[3]));
}
private IOException invalidHeader(Throwable cause) {
IOException ioe = invalidHeader();
ioe.initCause(cause);
return ioe;
}
/**
* IOException thrown by read when the configured input limit is exceeded.
*

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

@ -2110,7 +2110,7 @@ public class ReceivePack {
} catch (InputOverLimitIOException e) {
String msg = JGitText.get().tooManyCommands;
fatalError(msg);
throw new PackProtocolException(msg);
throw new PackProtocolException(msg, e);
} finally {
try {
close();

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java

@ -140,7 +140,7 @@ public class TestProtocol<C> extends TransportProtocol {
int n = handles.size();
uri = new URIish(SCHEME + "://test/conn" + n); //$NON-NLS-1$
} catch (URISyntaxException e) {
throw new IllegalStateException();
throw new IllegalStateException(e);
}
handles.put(uri, new Handle(req, remote));
return uri;

5
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java

@ -113,7 +113,10 @@ class TransportBundleFile extends Transport implements TransportBundle {
try {
src = new FileInputStream(bundle);
} catch (FileNotFoundException err) {
throw new TransportException(uri, JGitText.get().notFound);
TransportException te = new TransportException(uri,
JGitText.get().notFound);
te.initCause(err);
throw te;
}
return new BundleFetchConnection(this, src);
}

5
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java

@ -143,7 +143,10 @@ class TransportLocal extends Transport implements PackTransport {
.setFS(local != null ? local.getFS() : FS.DETECTED)
.setGitDir(remoteGitDir).build();
} catch (IOException err) {
throw new TransportException(uri, JGitText.get().notAGitDirectory);
TransportException te = new TransportException(uri,
JGitText.get().notAGitDirectory);
te.initCause(err);
throw te;
}
}

5
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

@ -266,7 +266,10 @@ public class URIish implements Serializable {
try {
val = parseHexByte(c1, c2);
} catch (ArrayIndexOutOfBoundsException e) {
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
URISyntaxException use = new URISyntaxException(s,
JGitText.get().cannotParseGitURIish);
use.initCause(e);
throw use;
}
os[j++] = (byte) val;
i += 2;

13
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java

@ -282,9 +282,12 @@ abstract class WalkEncryption {
String REGEX_TRANS = "(.+)/(.+)/(.+)"; //$NON-NLS-1$
}
static GeneralSecurityException securityError(String message) {
return new GeneralSecurityException(
static GeneralSecurityException securityError(String message,
Throwable cause) {
GeneralSecurityException e = new GeneralSecurityException(
MessageFormat.format(JGitText.get().encryptionError, message));
e.initCause(cause);
return e;
}
/**
@ -332,21 +335,21 @@ abstract class WalkEncryption {
try {
size = Integer.parseInt(keySize);
} catch (Exception e) {
throw securityError(X_KEY_SIZE + EMPTY + keySize);
throw securityError(X_KEY_SIZE + EMPTY + keySize, e);
}
final int iter;
try {
iter = Integer.parseInt(keyIter);
} catch (Exception e) {
throw securityError(X_KEY_ITER + EMPTY + keyIter);
throw securityError(X_KEY_ITER + EMPTY + keyIter, e);
}
final byte[] salt;
try {
salt = Hex.decode(keySalt.replaceAll(REGEX_WS, EMPTY));
} catch (Exception e) {
throw securityError(X_KEY_SALT + EMPTY + keySalt);
throw securityError(X_KEY_SALT + EMPTY + keySalt, e);
}
KeySpec keySpec = new PBEKeySpec(pass.toCharArray(), salt, iter, size);

2
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

@ -1159,7 +1159,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
} catch (CharacterCodingException e) {
// This should so never happen.
throw new RuntimeException(MessageFormat.format(
JGitText.get().unencodeableFile, getName()));
JGitText.get().unencodeableFile, getName()), e);
}
encodedNameLen = b.limit();

3
org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

@ -300,7 +300,8 @@ public class FileUtils {
} catch (InterruptedException e) {
throw new IOException(
MessageFormat.format(JGitText.get().renameFileFailed,
src.getAbsolutePath(), dst.getAbsolutePath()));
src.getAbsolutePath(), dst.getAbsolutePath()),
e);
}
}
throw new IOException(

15
org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java

@ -70,7 +70,7 @@ public class TimeoutInputStream extends FilterInputStream {
beginRead();
return super.read();
} catch (InterruptedIOException e) {
throw readTimedOut();
throw readTimedOut(e);
} finally {
endRead();
}
@ -89,7 +89,7 @@ public class TimeoutInputStream extends FilterInputStream {
beginRead();
return super.read(buf, off, cnt);
} catch (InterruptedIOException e) {
throw readTimedOut();
throw readTimedOut(e);
} finally {
endRead();
}
@ -102,7 +102,7 @@ public class TimeoutInputStream extends FilterInputStream {
beginRead();
return super.skip(cnt);
} catch (InterruptedIOException e) {
throw readTimedOut();
throw readTimedOut(e);
} finally {
endRead();
}
@ -116,8 +116,11 @@ public class TimeoutInputStream extends FilterInputStream {
myTimer.end();
}
private InterruptedIOException readTimedOut() {
return new InterruptedIOException(MessageFormat.format(
JGitText.get().readTimedOut, Integer.valueOf(timeout)));
private InterruptedIOException readTimedOut(InterruptedIOException e) {
InterruptedIOException interrupted = new InterruptedIOException(
MessageFormat.format(JGitText.get().readTimedOut,
Integer.valueOf(timeout)));
interrupted.initCause(e);
return interrupted;
}
}

17
org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java

@ -72,7 +72,7 @@ public class TimeoutOutputStream extends OutputStream {
beginWrite();
dst.write(b);
} catch (InterruptedIOException e) {
throw writeTimedOut();
throw writeTimedOut(e);
} finally {
endWrite();
}
@ -91,7 +91,7 @@ public class TimeoutOutputStream extends OutputStream {
beginWrite();
dst.write(buf, off, len);
} catch (InterruptedIOException e) {
throw writeTimedOut();
throw writeTimedOut(e);
} finally {
endWrite();
}
@ -104,7 +104,7 @@ public class TimeoutOutputStream extends OutputStream {
beginWrite();
dst.flush();
} catch (InterruptedIOException e) {
throw writeTimedOut();
throw writeTimedOut(e);
} finally {
endWrite();
}
@ -117,7 +117,7 @@ public class TimeoutOutputStream extends OutputStream {
beginWrite();
dst.close();
} catch (InterruptedIOException e) {
throw writeTimedOut();
throw writeTimedOut(e);
} finally {
endWrite();
}
@ -131,8 +131,11 @@ public class TimeoutOutputStream extends OutputStream {
myTimer.end();
}
private InterruptedIOException writeTimedOut() {
return new InterruptedIOException(MessageFormat.format(
JGitText.get().writeTimedOut, Integer.valueOf(timeout)));
private InterruptedIOException writeTimedOut(InterruptedIOException cause) {
InterruptedIOException e = new InterruptedIOException(
MessageFormat.format(JGitText.get().writeTimedOut,
Integer.valueOf(timeout)));
e.initCause(cause);
return e;
}
}

1
tools/BUILD

@ -78,6 +78,7 @@ java_package_configuration(
"-Xep:TypeParameterShadowing:ERROR",
"-Xep:TypeParameterUnusedInFormals:WARN",
"-Xep:URLEqualsHashCode:ERROR",
"-Xep:UnusedException:ERROR",
"-Xep:UnsynchronizedOverridesSynchronized:ERROR",
"-Xep:WaitNotInLoop:ERROR",
],

Loading…
Cancel
Save