Prechádzať zdrojové kódy

Java 7: Identical 'catch' branches in 'try' statement

Lars Grefer 6 rokov pred
rodič
commit
25c06be1eb

+ 1 - 5
core/src/main/java/org/springframework/security/authentication/DefaultAuthenticationEventPublisher.java

@@ -111,11 +111,7 @@ public class DefaultAuthenticationEventPublisher implements AuthenticationEventP
 			try {
 				event = constructor.newInstance(authentication, exception);
 			}
-			catch (IllegalAccessException ignored) {
-			}
-			catch (InstantiationException ignored) {
-			}
-			catch (InvocationTargetException ignored) {
+			catch (IllegalAccessException | InvocationTargetException | InstantiationException ignored) {
 			}
 		}
 

+ 2 - 7
core/src/main/java/org/springframework/security/authentication/ProviderManager.java

@@ -179,17 +179,12 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
 					break;
 				}
 			}
-			catch (AccountStatusException e) {
+			catch (AccountStatusException | InternalAuthenticationServiceException e) {
 				prepareException(e, authentication);
 				// SEC-546: Avoid polling additional providers if auth failure is due to
 				// invalid account status
 				throw e;
-			}
-			catch (InternalAuthenticationServiceException e) {
-				prepareException(e, authentication);
-				throw e;
-			}
-			catch (AuthenticationException e) {
+			} catch (AuthenticationException e) {
 				lastException = e;
 			}
 		}

+ 2 - 12
openid/src/main/java/org/springframework/security/openid/OpenID4JavaConsumer.java

@@ -116,11 +116,7 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
 				authReq.addExtension(fetchRequest);
 			}
 		}
-		catch (MessageException e) {
-			throw new OpenIDConsumerException(
-					"Error processing ConsumerManager authentication", e);
-		}
-		catch (ConsumerException e) {
+		catch (MessageException | ConsumerException e) {
 			throw new OpenIDConsumerException(
 					"Error processing ConsumerManager authentication", e);
 		}
@@ -164,13 +160,7 @@ public class OpenID4JavaConsumer implements OpenIDConsumer {
 			verification = consumerManager.verify(receivingURL.toString(), openidResp,
 					discovered);
 		}
-		catch (MessageException e) {
-			throw new OpenIDConsumerException("Error verifying openid response", e);
-		}
-		catch (DiscoveryException e) {
-			throw new OpenIDConsumerException("Error verifying openid response", e);
-		}
-		catch (AssociationException e) {
+		catch (MessageException | AssociationException | DiscoveryException e) {
 			throw new OpenIDConsumerException("Error verifying openid response", e);
 		}
 

+ 2 - 7
samples/xml/contacts/src/main/java/sample/contact/ClientApplication.java

@@ -77,10 +77,7 @@ public class ClientApplication {
 				System.out
 						.println("This client proxy factory does not have a setUsername(String) method");
 			}
-			catch (IllegalAccessException ignored) {
-				ignored.printStackTrace();
-			}
-			catch (InvocationTargetException ignored) {
+			catch (IllegalAccessException | InvocationTargetException ignored) {
 				ignored.printStackTrace();
 			}
 
@@ -98,9 +95,7 @@ public class ClientApplication {
 				System.out
 						.println("This client proxy factory does not have a setPassword(String) method");
 			}
-			catch (IllegalAccessException ignored) {
-			}
-			catch (InvocationTargetException ignored) {
+			catch (IllegalAccessException | InvocationTargetException ignored) {
 			}
 
 			System.out.println("Calling ContactManager '" + beanName + "'");

+ 2 - 12
web/src/main/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlMappableAttributesRetriever.java

@@ -114,19 +114,9 @@ public class WebXmlMappableAttributesRetriever implements ResourceLoaderAware,
 			doc = db.parse(aStream);
 			return doc;
 		}
-		catch (FactoryConfigurationError e) {
+		catch (FactoryConfigurationError | IOException | SAXException | ParserConfigurationException e) {
 			throw new RuntimeException("Unable to parse document object", e);
-		}
-		catch (ParserConfigurationException e) {
-			throw new RuntimeException("Unable to parse document object", e);
-		}
-		catch (SAXException e) {
-			throw new RuntimeException("Unable to parse document object", e);
-		}
-		catch (IOException e) {
-			throw new RuntimeException("Unable to parse document object", e);
-		}
-		finally {
+		} finally {
 			try {
 				aStream.close();
 			}