Skip to content

Commit

Permalink
Collapse identical catch blocks to reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
darxriggs committed Aug 13, 2019
1 parent 4382ed0 commit c72a8bb
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ public static Icon getIconByClassSpec(String spec) {
try {
Method getIconByClassSpec = IconSet.class.getMethod("getIconByClassSpec", Object.class);
return (Icon) getIconByClassSpec.invoke(IconSet.icons, spec);
} catch (NoSuchMethodException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// ignore
}
return IconSet.icons.getIconByClassSpec(spec);
Expand Down Expand Up @@ -227,9 +223,7 @@ public static Icon getIcon(@NonNull Action action) {
if (icon == null) {
icon = IconSet.icons.getIconByUrl(action.getIconFileName());
}
} catch (InvocationTargetException e) {
icon = null;
} catch (IllegalAccessException e) {
} catch (InvocationTargetException | IllegalAccessException e) {
icon = null;
}
return icon;
Expand Down Expand Up @@ -259,9 +253,7 @@ public static String getQualifiedUrl(@CheckForNull Icon icon) {
}
}
return null;
} catch (NoSuchFieldException e) {
// ignore we'll use a JellyContext
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException e) {
// ignore we'll use a JellyContext
}
JellyContext ctx = new JellyContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,7 @@ public void calcFillSettings(String field, Map<String, Object> attributes) {
}

}
} catch (AssertionError e) {
// ignore, we did the best we could
} catch (UnsupportedEncodingException e) {
} catch (AssertionError | UnsupportedEncodingException e) {
// ignore, we did the best we could
}
}
Expand Down Expand Up @@ -542,9 +540,7 @@ public void calcAutoCompleteSettings(String field, Map<String, Object> attribute
}

}
} catch (AssertionError e) {
// ignore, we did the best we could
} catch (UnsupportedEncodingException e) {
} catch (AssertionError | UnsupportedEncodingException e) {
// ignore, we did the best we could
}
}
Expand Down Expand Up @@ -601,9 +597,7 @@ public String toCheckUrl() {
}

}
} catch (AssertionError e) {
// ignore, we did the best we could
} catch (UnsupportedEncodingException e) {
} catch (AssertionError | UnsupportedEncodingException e) {
// ignore, we did the best we could
}
return checkUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,7 @@ public void exitLiteral(CQLParser.LiteralContext ctx) {
Class<?> enumClazz = Class.forName(enumClass);
Field field = enumClazz.getDeclaredField(enumConst);
literal = (Serializable) field.get(null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ Result name(@NonNull Credentials credentials, @NonNull Class<?> clazz) {
try {
CredentialsNameProvider nameProvider = nameWith.value().newInstance();
return new Result(nameProvider.getName(credentials), nameWith.priority());
} catch (ClassCastException e) {
// ignore
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
} catch (ClassCastException | InstantiationException | IllegalAccessException e) {
// ignore
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ public static <C extends Credentials> CredentialsResolver<Credentials, C> getRes
}
LOGGER.log(Level.SEVERE, "Resolver {0} for type {1} resolves to {2} which is not assignable to {1}",
new Object[]{resolver.getClass(), clazz, resolver.getToClass()});
} catch (InstantiationException e) {
LOGGER.log(Level.WARNING, "Could not instantiate resolver: " + resolveWith.value(), e);
return null;
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
LOGGER.log(Level.WARNING, "Could not instantiate resolver: " + resolveWith.value(), e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,9 +899,7 @@ public ModelObject getContext(String token) {
} catch (NoSuchMethodException e) {
// old Jenkins pre SECURITY-243
return User.get(token, false, Collections.emptyMap());
} catch (InvocationTargetException e) {
return null;
} catch (IllegalAccessException e) {
} catch (InvocationTargetException | IllegalAccessException e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,7 @@ public HttpResponse doCreateDomain(StaplerRequest req) throws ServletException,
try {
XMLUtils.safeTransform(new StreamSource(req.getReader()), new StreamResult(out));
out.close();
} catch (TransformerException e) {
throw new IOException("Failed to parse credential", e);
} catch (SAXException e) {
} catch (TransformerException | SAXException e) {
throw new IOException("Failed to parse credential", e);
}

Expand Down Expand Up @@ -810,9 +808,7 @@ public HttpResponse doCreateCredentials(StaplerRequest req) throws ServletExcept
try {
XMLUtils.safeTransform(new StreamSource(req.getReader()), new StreamResult(out));
out.close();
} catch (TransformerException e) {
throw new IOException("Failed to parse credential", e);
} catch (SAXException e) {
} catch (TransformerException | SAXException e) {
throw new IOException("Failed to parse credential", e);
}

Expand Down Expand Up @@ -1007,9 +1003,7 @@ public void updateByXml(Source source) throws IOException {
try {
XMLUtils.safeTransform(source, new StreamResult(out));
out.close();
} catch (TransformerException e) {
throw new IOException("Failed to parse credential", e);
} catch (SAXException e) {
} catch (TransformerException | SAXException e) {
throw new IOException("Failed to parse credential", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ protected static HierarchicalStreamReader safeXmlStreamReader(Source source) thr
try {
XMLUtils.safeTransform(source, new StreamResult(out));
out.close();
} catch (TransformerException e) {
throw new IOException("Failed to parse", e);
} catch (SAXException e) {
} catch (TransformerException | SAXException e) {
throw new IOException("Failed to parse", e);
}
return new XppDriver().createReader(new StringReader(out.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,7 @@ public synchronized KeyStore getKeyStore() {
}
try {
keyStore.load(new ByteArrayInputStream(keyStoreSource.getKeyStoreBytes()), toCharArray(password));
} catch (CertificateException e) {
LogRecord lr = new LogRecord(Level.WARNING, "Credentials ID {0}: Could not load keystore from {1}");
lr.setParameters(new Object[]{getId(), keyStoreSource});
lr.setThrown(e);
LOGGER.log(lr);
} catch (NoSuchAlgorithmException e) {
LogRecord lr = new LogRecord(Level.WARNING, "Credentials ID {0}: Could not load keystore from {1}");
lr.setParameters(new Object[]{getId(), keyStoreSource});
lr.setThrown(e);
LOGGER.log(lr);
} catch (IOException e) {
} catch (CertificateException | NoSuchAlgorithmException | IOException e) {
LogRecord lr = new LogRecord(Level.WARNING, "Credentials ID {0}: Could not load keystore from {1}");
lr.setParameters(new Object[]{getId(), keyStoreSource});
lr.setThrown(e);
Expand Down Expand Up @@ -336,13 +326,7 @@ protected static FormValidation validateCertificateKeystore(String type, byte[]
return FormValidation.ok(StringUtils
.defaultIfEmpty(StandardCertificateCredentials.NameProvider.getSubjectDN(keyStore),
buf.toString()));
} catch (KeyStoreException e) {
return FormValidation.warning(e, Messages.CertificateCredentialsImpl_LoadKeystoreFailed());
} catch (CertificateException e) {
return FormValidation.warning(e, Messages.CertificateCredentialsImpl_LoadKeystoreFailed());
} catch (NoSuchAlgorithmException e) {
return FormValidation.warning(e, Messages.CertificateCredentialsImpl_LoadKeystoreFailed());
} catch (IOException e) {
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
return FormValidation.warning(e, Messages.CertificateCredentialsImpl_LoadKeystoreFailed());
} finally {
if (passwordChars != null) {
Expand Down Expand Up @@ -698,13 +682,7 @@ public HttpResponse doUpload(@NonNull StaplerRequest req) throws ServletExceptio
Method m = XStream2.class.getMethod("addCriticalField", Class.class, String.class);
m.invoke(Items.XSTREAM2, CertificateCredentialsImpl.class, "keyStoreSource");
}
catch (IllegalAccessException e) {
throw new ExceptionInInitializerError(e);
}
catch (InvocationTargetException e) {
throw new ExceptionInInitializerError(e);
}
catch (NoSuchMethodException e) {
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new ExceptionInInitializerError(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public boolean matches(@NonNull Credentials item) {
try {
Object actual = readMethod.invoke(item);
return Objects.equals(expected, actual);
} catch (IllegalAccessException e) {
return false; // if we cannot access it then it's not a match
} catch (InvocationTargetException e) {
} catch (IllegalAccessException | InvocationTargetException e) {
return false; // if we cannot access it then it's not a match
}
}
Expand Down

0 comments on commit c72a8bb

Please sign in to comment.