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. 41
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

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

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

Loading…
Cancel
Save