Browse Source

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>
stable-4.10
David Pursehouse 7 years ago
parent
commit
0c259eaf1d
  1. 5
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
  2. 24
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
  3. 10
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
  4. 9
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
  5. 6
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  6. 4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
  7. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
  8. 5
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
  9. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
  10. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java
  11. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java

5
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

@ -178,10 +178,7 @@ public class ManifestParser extends DefaultHandler {
try { try {
xr.parse(new InputSource(inputStream)); xr.parse(new InputSource(inputStream));
} catch (SAXException e) { } catch (SAXException e) {
IOException error = new IOException( throw new IOException(RepoText.get().errorParsingManifestFile, e);
RepoText.get().errorParsingManifestFile);
error.initCause(e);
throw error;
} }
} }

24
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java

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

10
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java

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

9
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java

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

6
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

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

4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

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

6
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

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

5
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

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

8
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

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

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java

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

7
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java

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

Loading…
Cancel
Save