Collapse catch clauses

Use multi-catch for exceptions whenever possible.

See gh-9781
This commit is contained in:
Emanuel Campolo 2017-07-18 11:52:47 -03:00 committed by Phillip Webb
parent 4a189bdee7
commit 798fe5ed53
17 changed files with 19 additions and 76 deletions

View File

@ -107,16 +107,13 @@ public abstract class AbstractJmxCacheStatisticsProvider<C extends Cache>
Object attribute = getMBeanServer().getAttribute(objectName, attributeName);
return type.cast(attribute);
}
catch (MBeanException ex) {
catch (MBeanException | ReflectionException ex) {
throw new IllegalStateException(ex);
}
catch (AttributeNotFoundException ex) {
throw new IllegalStateException("Unexpected: MBean with name '" + objectName
+ "' " + "does not expose attribute with name " + attributeName, ex);
}
catch (ReflectionException ex) {
throw new IllegalStateException(ex);
}
catch (InstanceNotFoundException ex) {
logger.warn("Cache statistics are no longer available", ex);
return null;

View File

@ -255,10 +255,7 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
ClassUtils.forName(type, classLoader), considerHierarchy);
return result;
}
catch (ClassNotFoundException ex) {
return Collections.emptySet();
}
catch (NoClassDefFoundError ex) {
catch (ClassNotFoundException | NoClassDefFoundError ex) {
return Collections.emptySet();
}
}

View File

@ -240,10 +240,7 @@ public class HttpMessageConverters implements Iterable<HttpMessageConverter<?>>
try {
list.add(Class.forName(className));
}
catch (ClassNotFoundException ex) {
// Ignore
}
catch (NoClassDefFoundError ex) {
catch (ClassNotFoundException | NoClassDefFoundError ex) {
// Ignore
}
}

View File

@ -27,7 +27,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.city.City;
@ -135,9 +134,6 @@ public class MongoDataAutoConfigurationTests {
fail("Create FieldNamingStrategy interface should fail");
}
// We seem to have an inconsistent exception, accept either
catch (UnsatisfiedDependencyException ex) {
// Expected
}
catch (BeanCreationException ex) {
// Expected
}

View File

@ -131,10 +131,7 @@ public class AetherGrapeEngine implements GrapeEngine {
classLoader.addURL(file.toURI().toURL());
}
}
catch (ArtifactResolutionException ex) {
throw new DependencyResolutionFailedException(ex);
}
catch (MalformedURLException ex) {
catch (ArtifactResolutionException | MalformedURLException ex) {
throw new DependencyResolutionFailedException(ex);
}
return null;

View File

@ -80,10 +80,7 @@ public class ClassPathChangeUploader
try {
this.uri = new URL(url).toURI();
}
catch (URISyntaxException ex) {
throw new IllegalArgumentException("Malformed URL '" + url + "'");
}
catch (MalformedURLException ex) {
catch (URISyntaxException | MalformedURLException ex) {
throw new IllegalArgumentException("Malformed URL '" + url + "'");
}
this.requestFactory = requestFactory;

View File

@ -84,10 +84,7 @@ public class HttpTunnelConnection implements TunnelConnection {
try {
this.uri = new URL(url).toURI();
}
catch (URISyntaxException ex) {
throw new IllegalArgumentException("Malformed URL '" + url + "'");
}
catch (MalformedURLException ex) {
catch (URISyntaxException | MalformedURLException ex) {
throw new IllegalArgumentException("Malformed URL '" + url + "'");
}
this.requestFactory = requestFactory;

View File

@ -371,9 +371,6 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
addDependencies(urls);
return urls.toArray(new URL[urls.size()]);
}
catch (MalformedURLException ex) {
throw new MojoExecutionException("Unable to build classpath", ex);
}
catch (IOException ex) {
throw new MojoExecutionException("Unable to build classpath", ex);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -73,10 +73,7 @@ class SpringApplicationAdminClient {
throw new MojoExecutionException("Failed to retrieve Ready attribute",
ex.getCause());
}
catch (MBeanException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
catch (IOException ex) {
catch (MBeanException | IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}

View File

@ -94,11 +94,7 @@ public class StartMojo extends AbstractRunMojo {
try {
waitForSpringApplication();
}
catch (MojoExecutionException ex) {
runProcess.kill();
throw ex;
}
catch (MojoFailureException ex) {
catch (MojoExecutionException | MojoFailureException ex) {
runProcess.kill();
throw ex;
}

View File

@ -191,10 +191,7 @@ class BeanDefinitionLoader {
try {
return load(ClassUtils.forName(resolvedSource, null));
}
catch (IllegalArgumentException ex) {
// swallow exception and continue
}
catch (ClassNotFoundException ex) {
catch (IllegalArgumentException | ClassNotFoundException ex) {
// swallow exception and continue
}
// Attempt as resources

View File

@ -91,10 +91,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor
try {
return beanFactory.getBeanNamesForType(Class.forName(type), true, false);
}
catch (ClassNotFoundException ex) {
// Ignore
}
catch (NoClassDefFoundError ex) {
catch (ClassNotFoundException | NoClassDefFoundError ex) {
// Ignore
}
return NO_BEANS;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -67,10 +67,7 @@ public class BitronixDependentBeanFactoryPostProcessor
try {
return beanFactory.getBeanNamesForType(Class.forName(type), true, false);
}
catch (ClassNotFoundException ex) {
// Ignore
}
catch (NoClassDefFoundError ex) {
catch (ClassNotFoundException | NoClassDefFoundError ex) {
// Ignore
}
return NO_BEANS;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -70,10 +70,7 @@ public class NarayanaBeanFactoryPostProcessor
try {
return beanFactory.getBeanNamesForType(Class.forName(type), true, false);
}
catch (ClassNotFoundException ex) {
// Ignore
}
catch (NoClassDefFoundError ex) {
catch (ClassNotFoundException | NoClassDefFoundError ex) {
// Ignore
}
return NO_BEANS;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -78,11 +78,7 @@ public class SpringPackageScanClassResolver extends DefaultPackageScanClassResol
MetadataReader reader = readerFactory.getMetadataReader(resource);
return ClassUtils.forName(reader.getClassMetadata().getClassName(), loader);
}
catch (ClassNotFoundException ex) {
handleFailure(resource, ex);
return null;
}
catch (LinkageError ex) {
catch (ClassNotFoundException | LinkageError ex) {
handleFailure(resource, ex);
return null;
}

View File

@ -58,10 +58,7 @@ class TomcatErrorPage {
.instantiateClass(ClassUtils.forName(ERROR_PAGE_CLASS, null));
}
}
catch (ClassNotFoundException ex) {
// Swallow and continue
}
catch (LinkageError ex) {
catch (ClassNotFoundException | LinkageError ex) {
// Swallow and continue
}
return null;

View File

@ -273,13 +273,7 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
+ elapsedTime + " ms");
}
}
catch (RuntimeException ex) {
logger.error("Context initialization failed", ex);
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw ex;
}
catch (Error ex) {
catch (RuntimeException | Error ex) {
logger.error("Context initialization failed", ex);
servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);