Replace explicit calls to initCause where possible

Where the exception being thrown has a constructor that takes a
Throwable, use that instead of instantiating the exception and then
explicitly calling initCause.

Change-Id: I06a0df407ba751a7af8c1c4a46f9e2714f13dbe3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2017-12-19 14:05:40 +09:00
parent 19864c6c02
commit 0c259eaf1d
11 changed files with 34 additions and 54 deletions

View File

@ -178,10 +178,7 @@ public void read(InputStream inputStream) throws IOException {
try {
xr.parse(new InputSource(inputStream));
} catch (SAXException e) {
IOException error = new IOException(
RepoText.get().errorParsingManifestFile);
error.initCause(e);
throw error;
throw new IOException(RepoText.get().errorParsingManifestFile, e);
}
}

View File

@ -247,34 +247,30 @@ public void onConfigChanged(ConfigChangedEvent event) {
private void loadSystemConfig() throws IOException {
try {
systemConfig.load();
} catch (ConfigInvalidException e1) {
IOException e2 = new IOException(MessageFormat.format(JGitText
} catch (ConfigInvalidException e) {
throw new IOException(MessageFormat.format(JGitText
.get().systemConfigFileInvalid, systemConfig.getFile()
.getAbsolutePath(), e1));
e2.initCause(e1);
throw e2;
.getAbsolutePath(),
e), e);
}
}
private void loadUserConfig() throws IOException {
try {
userConfig.load();
} catch (ConfigInvalidException e1) {
IOException e2 = new IOException(MessageFormat.format(JGitText
} catch (ConfigInvalidException e) {
throw new IOException(MessageFormat.format(JGitText
.get().userConfigFileInvalid, userConfig.getFile()
.getAbsolutePath(), e1));
e2.initCause(e1);
throw e2;
.getAbsolutePath(),
e), e);
}
}
private void loadRepoConfig() throws IOException {
try {
repoConfig.load();
} catch (ConfigInvalidException e1) {
IOException e2 = new IOException(JGitText.get().unknownRepositoryFormat);
e2.initCause(e1);
throw e2;
} catch (ConfigInvalidException e) {
throw new IOException(JGitText.get().unknownRepositoryFormat, e);
}
}

View File

@ -97,12 +97,10 @@ public static PackBitmapIndex open(
try {
return read(fd, packIndex, reverseIndex);
} catch (IOException ioe) {
final String path = idxFile.getAbsolutePath();
final IOException err;
err = new IOException(MessageFormat.format(
JGitText.get().unreadablePackIndex, path));
err.initCause(ioe);
throw err;
throw new IOException(MessageFormat
.format(JGitText.get().unreadablePackIndex,
idxFile.getAbsolutePath()),
ioe);
} finally {
try {
fd.close();

View File

@ -99,11 +99,10 @@ public static PackIndex open(final File idxFile) throws IOException {
try {
return read(fd);
} catch (IOException ioe) {
final String path = idxFile.getAbsolutePath();
final IOException err;
err = new IOException(MessageFormat.format(JGitText.get().unreadablePackIndex, path));
err.initCause(ioe);
throw err;
throw new IOException(MessageFormat
.format(JGitText.get().unreadablePackIndex,
idxFile.getAbsolutePath()),
ioe);
} finally {
try {
fd.close();

View File

@ -1184,10 +1184,8 @@ LooseRef scanRef(LooseRef ref, String name) throws IOException {
n--;
String content = RawParseUtils.decode(buf, 0, n);
IOException ioException = new IOException(MessageFormat.format(JGitText.get().notARef,
name, content));
ioException.initCause(notRef);
throw ioException;
throw new IOException(MessageFormat.format(JGitText.get().notARef,
name, content), notRef);
}
return new LooseUnpeeled(otherSnapshot, name, id);
}

View File

@ -1531,9 +1531,7 @@ public void run() {
if (err instanceof IOException)
throw (IOException) err;
IOException fail = new IOException(err.getMessage());
fail.initCause(err);
throw fail;
throw new IOException(err.getMessage(), err);
}
endPhase(monitor);
}

View File

@ -538,11 +538,9 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
.equals(localIgnoreSubmoduleMode))
continue;
} catch (ConfigInvalidException e) {
IOException e1 = new IOException(MessageFormat.format(
throw new IOException(MessageFormat.format(
JGitText.get().invalidIgnoreParamSubmodule,
smw.getPath()));
e1.initCause(e);
throw e1;
smw.getPath()), e);
}
Repository subRepo = smw.getRepository();
if (subRepo != null) {

View File

@ -171,9 +171,8 @@ public void load() throws IOException, ConfigInvalidException {
clear();
snapshot = newSnapshot;
} catch (IOException e) {
final IOException e2 = new IOException(MessageFormat.format(JGitText.get().cannotReadFile, getFile()));
e2.initCause(e);
throw e2;
throw new IOException(MessageFormat
.format(JGitText.get().cannotReadFile, getFile()), e);
} catch (ConfigInvalidException e) {
throw new ConfigInvalidException(MessageFormat.format(JGitText.get().cannotReadFile, getFile()), e);
}

View File

@ -707,10 +707,10 @@ void list() throws IOException {
try {
xr.parse(new InputSource(in));
} catch (SAXException parsingError) {
final IOException p;
p = new IOException(MessageFormat.format(JGitText.get().errorListing, prefix));
p.initCause(parsingError);
throw p;
throw new IOException(
MessageFormat.format(
JGitText.get().errorListing, prefix),
parsingError);
} finally {
in.close();
}

View File

@ -549,9 +549,7 @@ void configureRequest(HttpConnection conn) throws IOException {
conn.setRequestProperty(HDR_AUTHORIZATION, getType().getSchemeName()
+ " " + Base64.encodeBytes(token)); //$NON-NLS-1$
} catch (GSSException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e);
}
}
}

View File

@ -115,10 +115,9 @@ protected void validateImpl(final HttpURLConnection u, final String prefix,
}
IOException error(final Throwable why) {
final IOException e;
e = new IOException(MessageFormat.format(JGitText.get().encryptionError, why.getMessage()));
e.initCause(why);
return e;
return new IOException(MessageFormat
.format(JGitText.get().encryptionError,
why.getMessage()), why);
}
private static class NoEncryption extends WalkEncryption {