Browse Source

Do not ignore secondary failure

When another exception is thrown while handling another exception, that
exception can be attached to the original exception since Java 7
(Throwable#getSuppressed). Attach the secondary exception to the
original exception instead of throwing it away.

Change-Id: Ia093b8207714f2638e0343bc45a83d4342947505
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
stable-5.5
Masaya Suzuki 6 years ago committed by Terry Parker
parent
commit
ca360ea2b5
  1. 53
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

53
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -1017,27 +1017,23 @@ public class UploadPack {
if (!err.isOutput() && err.getMessage() != null) {
try {
pckOut.writeString("ERR " + err.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
err.setOutput();
} catch (Throwable err2) {
// Ignore this secondary failure (and not mark output).
} catch (IOException e) {
err.addSuppressed(e);
throw err;
}
err.setOutput();
}
throw err;
} catch (IOException | RuntimeException | Error err) {
boolean output = false;
String msg = err instanceof PackProtocolException ? err.getMessage()
: JGitText.get().internalServerError;
try {
String msg = err instanceof PackProtocolException
? err.getMessage()
: JGitText.get().internalServerError;
pckOut.writeString("ERR " + msg + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
output = true;
} catch (Throwable err2) {
// Ignore this secondary failure, leave output false.
}
if (output) {
throw new UploadPackInternalServerErrorException(err);
} catch (IOException e) {
err.addSuppressed(e);
throw err;
}
throw err;
throw new UploadPackInternalServerErrorException(err);
} finally {
if (!sendPack && !biDirectionalPipe) {
while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) {
@ -2077,31 +2073,26 @@ public class UploadPack {
// This was already reported on (below).
throw noPack;
} catch (IOException | RuntimeException | Error err) {
if (reportInternalServerErrorOverSideband()) {
throw new UploadPackInternalServerErrorException(err);
} else {
try {
reportInternalServerErrorOverSideband();
} catch (IOException e) {
err.addSuppressed(e);
throw err;
}
throw new UploadPackInternalServerErrorException(err);
}
} else {
sendPack(false, req, accumulator, allTags, unshallowCommits, deepenNots);
}
}
private boolean reportInternalServerErrorOverSideband() {
try {
@SuppressWarnings("resource" /* java 7 */)
SideBandOutputStream err = new SideBandOutputStream(
SideBandOutputStream.CH_ERROR,
SideBandOutputStream.SMALL_BUF,
rawOut);
err.write(Constants.encode(JGitText.get().internalServerError));
err.flush();
return true;
} catch (Throwable cannotReport) {
// Ignore the reason. This is a secondary failure.
return false;
}
private void reportInternalServerErrorOverSideband() throws IOException {
@SuppressWarnings("resource" /* java 7 */)
SideBandOutputStream err = new SideBandOutputStream(
SideBandOutputStream.CH_ERROR, SideBandOutputStream.SMALL_BUF,
rawOut);
err.write(Constants.encode(JGitText.get().internalServerError));
err.flush();
}
/**

Loading…
Cancel
Save