diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2020-01-27 09:47:05 +0900 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2020-01-27 14:40:08 +0100 |
commit | 4cc13297ccf1fa3e982bbb5638162b3bad63f93c (patch) | |
tree | 3f0b0c0aead716773d569e0b2eb1efb3b6f02081 /org.eclipse.jgit.pgm | |
parent | 0e4a717870f64e667e657650f12e93d477d369c3 (diff) | |
download | jgit-4cc13297ccf1fa3e982bbb5638162b3bad63f93c.tar.gz jgit-4cc13297ccf1fa3e982bbb5638162b3bad63f93c.zip |
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>
Diffstat (limited to 'org.eclipse.jgit.pgm')
10 files changed, 21 insertions, 11 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java index 455abcd37c..98724bfceb 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java +++ b/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); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 243e99fdf2..8f80d6d70e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/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(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java index cbb5d846ba..f570f7f99b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java +++ b/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); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java index 8c39886031..b408b78f3c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java +++ b/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 { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java index 69c8eb5701..36103f2e6f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java +++ b/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); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index ddd48da466..8d884c12db 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/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)); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java index 6f0aba377e..49f7ada457 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java +++ b/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)); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java index 07a1bb801f..d8604726ab 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java +++ b/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, diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java index f521775c7c..8b2bed36a7 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java +++ b/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, diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java index fa96361681..357886d0fa 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java +++ b/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, |