From 0c259eaf1db076837768512deb6c251c86e67941 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 19 Dec 2017 14:05:40 +0900 Subject: [PATCH] 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 --- .../eclipse/jgit/gitrepo/ManifestParser.java | 5 +--- .../internal/storage/file/FileRepository.java | 24 ++++++++----------- .../storage/file/PackBitmapIndex.java | 10 ++++---- .../jgit/internal/storage/file/PackIndex.java | 9 ++++--- .../internal/storage/file/RefDirectory.java | 6 ++--- .../internal/storage/pack/PackWriter.java | 4 +--- .../src/org/eclipse/jgit/lib/IndexDiff.java | 6 ++--- .../jgit/storage/file/FileBasedConfig.java | 5 ++-- .../org/eclipse/jgit/transport/AmazonS3.java | 8 +++---- .../jgit/transport/HttpAuthMethod.java | 4 +--- .../jgit/transport/WalkEncryption.java | 7 +++--- 11 files changed, 34 insertions(+), 54 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java index 4ec45db4f1..929ffac114 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java @@ -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); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 1a89cff209..9e2fb55de0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/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 { 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); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java index 181951c650..21a1c7fcb3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java @@ -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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java index a7000e89d7..acfd9c4719 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java @@ -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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 8b3b794129..20302d124b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -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); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 2cf4d4b559..71d10ac45d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/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) throw (IOException) err; - IOException fail = new IOException(err.getMessage()); - fail.initCause(err); - throw fail; + throw new IOException(err.getMessage(), err); } endPhase(monitor); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index b3158df142..87086cbde0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -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) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index 32a8bfdbb9..9927daf3d5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -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); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 13f91676ad..0690397078 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -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(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java index bbc964227f..0c54027c7f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java @@ -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); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java index 333e09d463..38e8e9f152 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java @@ -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 { -- 2.39.5