From 25c06be1eb757c042fd1cbb4334e687aed3cb739 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Fri, 9 Aug 2019 00:48:57 +0200 Subject: [PATCH] Java 7: Identical 'catch' branches in 'try' statement --- .../DefaultAuthenticationEventPublisher.java | 6 +----- .../security/authentication/ProviderManager.java | 9 ++------- .../security/openid/OpenID4JavaConsumer.java | 14 ++------------ .../java/sample/contact/ClientApplication.java | 9 ++------- .../j2ee/WebXmlMappableAttributesRetriever.java | 14 ++------------ 5 files changed, 9 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/org/springframework/security/authentication/DefaultAuthenticationEventPublisher.java b/core/src/main/java/org/springframework/security/authentication/DefaultAuthenticationEventPublisher.java index 1decb2f5ab..2d0015fc55 100644 --- a/core/src/main/java/org/springframework/security/authentication/DefaultAuthenticationEventPublisher.java +++ b/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) { } } diff --git a/core/src/main/java/org/springframework/security/authentication/ProviderManager.java b/core/src/main/java/org/springframework/security/authentication/ProviderManager.java index 4e78144084..b483670950 100644 --- a/core/src/main/java/org/springframework/security/authentication/ProviderManager.java +++ b/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; } } diff --git a/openid/src/main/java/org/springframework/security/openid/OpenID4JavaConsumer.java b/openid/src/main/java/org/springframework/security/openid/OpenID4JavaConsumer.java index f51fc74455..6f6bb81e6c 100644 --- a/openid/src/main/java/org/springframework/security/openid/OpenID4JavaConsumer.java +++ b/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); } diff --git a/samples/xml/contacts/src/main/java/sample/contact/ClientApplication.java b/samples/xml/contacts/src/main/java/sample/contact/ClientApplication.java index 3d4d736f61..c93a5d6c68 100644 --- a/samples/xml/contacts/src/main/java/sample/contact/ClientApplication.java +++ b/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 + "'"); diff --git a/web/src/main/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlMappableAttributesRetriever.java b/web/src/main/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlMappableAttributesRetriever.java index a8905b67ab..4c368412dc 100755 --- a/web/src/main/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlMappableAttributesRetriever.java +++ b/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(); }