]> source.dussan.org Git - jgit.git/commitdiff
Replace explicit calls to initCause where possible 63/114363/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 19 Dec 2017 05:05:40 +0000 (14:05 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 19 Dec 2017 23:02:34 +0000 (08:02 +0900)
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>
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java

index 4ec45db4f18dca6d18eaf10de83ee6d66ae93e2f..929ffac114483f38f796e3fef4ff7df074505da8 100644 (file)
@@ -178,10 +178,7 @@ public class ManifestParser extends DefaultHandler {
                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);
                }
        }
 
index 1a89cff20900495d90e513977e95db13129976cb..9e2fb55de0106ff8572a40861130c5839fe69905 100644 (file)
@@ -247,34 +247,30 @@ public class FileRepository extends Repository {
        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);
                }
        }
 
index 181951c6508d3402fc3c77bdb0a2eef0aae09201..21a1c7fcb3294026f3595aea488b9e8d10d6c977 100644 (file)
@@ -97,12 +97,10 @@ public abstract class PackBitmapIndex {
                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();
index a7000e89d72f57e2d43f5e0b6073f1fa61dc26a6..acfd9c4719ec7e83a87ae4460ff935a956fce1cd 100644 (file)
@@ -99,11 +99,10 @@ public abstract class PackIndex
                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();
index 8b3b794129e23750b14b732ef56fad2b99fcb85f..20302d124b79b57decd69884b52fe46b6ce7a554 100644 (file)
@@ -1184,10 +1184,8 @@ public class RefDirectory extends RefDatabase {
                                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);
        }
index 2cf4d4b559f41e49dab0c80b105396ffd4ae8326..71d10ac45d1722cbee91e48b8a785dee1eb7b416 100644 (file)
@@ -1531,9 +1531,7 @@ public class PackWriter implements AutoCloseable {
                        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);
        }
index b3158df1425a0cbec73d2cea5a934ad4ba6c92e2..87086cbde0590f1afb9033ab73a0c898828db689 100644 (file)
@@ -538,11 +538,9 @@ public class IndexDiff {
                                                        .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) {
index 32a8bfdbb96783d9bbc97543868837d8f8660eb7..9927daf3d5154af6dc0cafc3425b8d513e95f2aa 100644 (file)
@@ -171,9 +171,8 @@ public class FileBasedConfig extends StoredConfig {
                        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);
                }
index 13f91676ade091f280b53c5d0de77f90a9149655..0690397078f2aa5490b91c5a796cd252a8e2d9c0 100644 (file)
@@ -707,10 +707,10 @@ public class AmazonS3 {
                                        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();
                                        }
index bbc964227f50f63dfea75d6cee276dddb02ddbaa..0c54027c7fafab218e4b55d25f7936079c9da911 100644 (file)
@@ -549,9 +549,7 @@ abstract class HttpAuthMethod {
                                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);
                        }
                }
        }
index 333e09d46331a4424c77f46e9c7b5611bf7170fc..38e8e9f152b75af9de8dd5050e1b4f14f8594a99 100644 (file)
@@ -115,10 +115,9 @@ abstract class WalkEncryption {
        }
 
        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 {