diff options
author | Darius Jokilehto <dariusjokilehto+os@gmail.com> | 2022-02-04 16:13:27 +0000 |
---|---|---|
committer | Darius Jokilehto <dariusjokilehto+os@gmail.com> | 2022-02-08 09:52:03 +0000 |
commit | 78c9b9260a5287d09c87b407e396021590714513 (patch) | |
tree | fc6a40d2ac048c356795cba27adb77effa2fd260 /org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java | |
parent | 2cc0009737182822a82731f523c0f6ded7601ddb (diff) | |
download | jgit-78c9b9260a5287d09c87b407e396021590714513.tar.gz jgit-78c9b9260a5287d09c87b407e396021590714513.zip |
Stop initCause throwing in readAdvertisedRefs
BasePackConnection::readAdvertisedRefsImpl was creating an exception by
calling `noRepository`, and then blindly calling `initCause` on it. As
`noRepository` can be overridden, it's not guaranteed to be missing a
cause.
BasePackPushConnection overrides `noRepository` and initiates a fetch,
which may throw a `NoRemoteRepositoryException` with a cause.
In this case calling `initCause` threw an `IllegalStateException`.
In order to throw the correct exception, we now return the
BasePackPushConnection exception and suppress the one thrown by
BasePackConnection
Bug: 578511
Change-Id: Ic1018b214be1e83d895979ee6c7cbce3f6765f6f
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java index 3826bf7401..09c559d7b5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java @@ -210,9 +210,7 @@ abstract class BasePackConnection extends BaseConnection { try { line = readLine(); } catch (EOFException e) { - TransportException noRepo = noRepository(); - noRepo.initCause(e); - throw noRepo; + throw noRepository(e); } if (line != null && VERSION_1.equals(line)) { // Same as V0, except for this extra line. We shouldn't get @@ -567,11 +565,14 @@ abstract class BasePackConnection extends BaseConnection { * * Subclasses may override this method to provide better diagnostics. * + * @param cause + * root cause exception * @return a TransportException saying a repository cannot be found and * possibly why. */ - protected TransportException noRepository() { - return new NoRemoteRepositoryException(uri, JGitText.get().notFound); + protected TransportException noRepository(Throwable cause) { + return new NoRemoteRepositoryException(uri, JGitText.get().notFound, + cause); } /** |