From e12c8310eb663be77624fde879e9c853f375d3d7 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 16 Feb 2006 16:44:35 +0000 Subject: [PATCH] Remove unnecessary default constructors which throw IllegalArgumentException. Favours compile time over runtime errors. --- .../org/acegisecurity/SecurityConfig.java | 4 ---- .../acl/basic/NamedEntityObjectIdentity.java | 4 ---- .../adapters/PrincipalAcegiUserToken.java | 4 ---- .../intercept/InterceptorStatusToken.java | 4 ---- .../intercept/web/FilterInvocation.java | 4 ---- .../providers/cas/TicketResponse.java | 4 ---- .../org/acegisecurity/userdetails/User.java | 22 +++++-------------- .../acegisecurity/SecurityConfigTests.java | 10 +++++---- .../basic/NamedEntityObjectIdentityTests.java | 10 +++++---- ...stractAdapterAuthenticationTokenTests.java | 13 ----------- .../PrincipalAcegiUserTokenTests.java | 12 +++++----- .../InterceptorStatusTokenTests.java | 10 +++++---- ...InvocationDefinitionSourceEditorTests.java | 10 +++++---- ...nDefinitionSourceEditorWithPathsTests.java | 10 +++++---- .../intercept/web/FilterInvocationTests.java | 10 +++++---- .../providers/cas/TicketResponseTests.java | 10 +++++---- .../acegisecurity/userdetails/UserTests.java | 10 +++++---- 17 files changed, 61 insertions(+), 90 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/SecurityConfig.java b/core/src/main/java/org/acegisecurity/SecurityConfig.java index 7b1a8158fb..e792ce717a 100644 --- a/core/src/main/java/org/acegisecurity/SecurityConfig.java +++ b/core/src/main/java/org/acegisecurity/SecurityConfig.java @@ -32,10 +32,6 @@ public class SecurityConfig implements ConfigAttribute { this.attrib = config; } - protected SecurityConfig() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - //~ Methods ================================================================ public String getAttribute() { diff --git a/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java b/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java index 5b2e96756e..c14e81847e 100644 --- a/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java +++ b/core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java @@ -46,10 +46,6 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity { this.id = id; } - protected NamedEntityObjectIdentity() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - /** * Creates the NamedEntityObjectIdentity based on the passed * object instance. The passed object must provide a getId() diff --git a/core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java b/core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java index 1af70f4a3e..1b27551f4f 100644 --- a/core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java +++ b/core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java @@ -45,10 +45,6 @@ public class PrincipalAcegiUserToken extends AbstractAdapterAuthenticationToken this.principal = principal; } - protected PrincipalAcegiUserToken() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - //~ Methods ================================================================ public Object getCredentials() { diff --git a/core/src/main/java/org/acegisecurity/intercept/InterceptorStatusToken.java b/core/src/main/java/org/acegisecurity/intercept/InterceptorStatusToken.java index 23f82a7e21..299cc74ace 100644 --- a/core/src/main/java/org/acegisecurity/intercept/InterceptorStatusToken.java +++ b/core/src/main/java/org/acegisecurity/intercept/InterceptorStatusToken.java @@ -51,10 +51,6 @@ public class InterceptorStatusToken { this.secureObject = secureObject; } - protected InterceptorStatusToken() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - //~ Methods ================================================================ public ConfigAttributeDefinition getAttr() { diff --git a/core/src/main/java/org/acegisecurity/intercept/web/FilterInvocation.java b/core/src/main/java/org/acegisecurity/intercept/web/FilterInvocation.java index 8b059756b7..e88af85bd5 100644 --- a/core/src/main/java/org/acegisecurity/intercept/web/FilterInvocation.java +++ b/core/src/main/java/org/acegisecurity/intercept/web/FilterInvocation.java @@ -71,10 +71,6 @@ public class FilterInvocation { this.chain = chain; } - protected FilterInvocation() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - //~ Methods ================================================================ public FilterChain getChain() { diff --git a/core/src/main/java/org/acegisecurity/providers/cas/TicketResponse.java b/core/src/main/java/org/acegisecurity/providers/cas/TicketResponse.java index dbf6673ad9..4673290479 100644 --- a/core/src/main/java/org/acegisecurity/providers/cas/TicketResponse.java +++ b/core/src/main/java/org/acegisecurity/providers/cas/TicketResponse.java @@ -72,10 +72,6 @@ public class TicketResponse { this.proxyGrantingTicketIou = proxyGrantingTicketIou; } - protected TicketResponse() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - //~ Methods ================================================================ public String getProxyGrantingTicketIou() { diff --git a/core/src/main/java/org/acegisecurity/userdetails/User.java b/core/src/main/java/org/acegisecurity/userdetails/User.java index a61326deda..0ca42645a9 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/User.java +++ b/core/src/main/java/org/acegisecurity/userdetails/User.java @@ -35,8 +35,6 @@ import org.springframework.util.Assert; public class User implements UserDetails { //~ Instance fields ======================================================== - // ~ Instance fields - // ======================================================== private String password; private String username; private GrantedAuthority[] authorities; @@ -47,12 +45,6 @@ public class User implements UserDetails { //~ Constructors =========================================================== - // ~ Constructors - // =========================================================== - protected User() { - throw new IllegalArgumentException("Cannot use default constructor"); - } - /** * Construct the User with the details required by {@link * DaoAuthenticationProvider}. @@ -192,8 +184,6 @@ public class User implements UserDetails { return username; } - // ~ Methods - // ================================================================ public int hashCode() { int code = 9792; @@ -260,13 +250,13 @@ public class User implements UserDetails { public String toString() { StringBuffer sb = new StringBuffer(); - sb.append(super.toString() + ": "); - sb.append("Username: " + this.username + "; "); + sb.append(super.toString()).append(": "); + sb.append("Username: ").append(this.username).append("; "); sb.append("Password: [PROTECTED]; "); - sb.append("Enabled: " + this.enabled + "; "); - sb.append("AccountNonExpired: " + this.accountNonExpired + "; "); - sb.append("credentialsNonExpired: " + this.credentialsNonExpired + "; "); - sb.append("AccountNonLocked: " + this.accountNonLocked + "; "); + sb.append("Enabled: ").append(this.enabled).append("; "); + sb.append("AccountNonExpired: ").append(this.accountNonExpired).append("; "); + sb.append("credentialsNonExpired: ").append(this.credentialsNonExpired).append("; "); + sb.append("AccountNonLocked: ").append(this.accountNonLocked).append("; "); if (this.getAuthorities() != null) { sb.append("Granted Authorities: "); diff --git a/core/src/test/java/org/acegisecurity/SecurityConfigTests.java b/core/src/test/java/org/acegisecurity/SecurityConfigTests.java index 6b50abc56e..b5136a470b 100644 --- a/core/src/test/java/org/acegisecurity/SecurityConfigTests.java +++ b/core/src/test/java/org/acegisecurity/SecurityConfigTests.java @@ -49,12 +49,14 @@ public class SecurityConfigTests extends TestCase { SecurityConfig config = new SecurityConfig("TEST"); assertEquals("TEST".hashCode(), config.hashCode()); } + + public void testNoArgConstructorDoesntExist() { + Class clazz = SecurityConfig.class; - public void testNoArgsConstructor() { try { - new SecurityConfig(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentityTests.java b/core/src/test/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentityTests.java index 81107ff14d..7facc8dcef 100644 --- a/core/src/test/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentityTests.java +++ b/core/src/test/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentityTests.java @@ -75,11 +75,13 @@ public class NamedEntityObjectIdentityTests extends TestCase { } } - public void testDefaultConstructorRejected() { + public void testNoArgConstructorDoesntExist() { + Class clazz = NamedEntityObjectIdentity.class; + try { - new NamedEntityObjectIdentity(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationTokenTests.java b/core/src/test/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationTokenTests.java index 7f4da5871d..c42d4cd8a6 100644 --- a/core/src/test/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationTokenTests.java +++ b/core/src/test/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationTokenTests.java @@ -71,15 +71,6 @@ public class AbstractAdapterAuthenticationTokenTests extends TestCase { assertTrue(!token.isUserInRole("ROLE_XXXX")); } - public void testNoArgsConstructor() { - try { - new MockDecisionManagerImpl(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - assertTrue(true); - } - } - public void testObjectsEquals() throws Exception { MockDecisionManagerImpl token1 = new MockDecisionManagerImpl("my_password", "Test", "Password", @@ -148,10 +139,6 @@ public class AbstractAdapterAuthenticationTokenTests extends TestCase { this.password = password; } - private MockDecisionManagerImpl() { - throw new IllegalArgumentException(); - } - public Object getCredentials() { return this.password; } diff --git a/core/src/test/java/org/acegisecurity/adapters/PrincipalAcegiUserTokenTests.java b/core/src/test/java/org/acegisecurity/adapters/PrincipalAcegiUserTokenTests.java index 5793015ee5..4d8e775ca6 100644 --- a/core/src/test/java/org/acegisecurity/adapters/PrincipalAcegiUserTokenTests.java +++ b/core/src/test/java/org/acegisecurity/adapters/PrincipalAcegiUserTokenTests.java @@ -59,12 +59,14 @@ public class PrincipalAcegiUserTokenTests extends TestCase { assertEquals("Test", token.getName()); } - public void testNoArgsConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = PrincipalAcegiUserToken.class; + try { - new PrincipalAcegiUserToken(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } - } + } } diff --git a/core/src/test/java/org/acegisecurity/intercept/InterceptorStatusTokenTests.java b/core/src/test/java/org/acegisecurity/intercept/InterceptorStatusTokenTests.java index b4c3d1bf25..757def63df 100644 --- a/core/src/test/java/org/acegisecurity/intercept/InterceptorStatusTokenTests.java +++ b/core/src/test/java/org/acegisecurity/intercept/InterceptorStatusTokenTests.java @@ -48,11 +48,13 @@ public class InterceptorStatusTokenTests extends TestCase { junit.textui.TestRunner.run(InterceptorStatusTokenTests.class); } - public void testDefaultConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = InterceptorStatusToken.class; + try { - new InterceptorStatusToken(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorTests.java b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorTests.java index de0ab2d2dc..f0d1402747 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorTests.java +++ b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorTests.java @@ -154,11 +154,13 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase { assertEquals(2, map.getMapSize()); } - public void testNoArgsConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = RegExpBasedFilterInvocationDefinitionMap.EntryHolder.class; + try { - new RegExpBasedFilterInvocationDefinitionMap().new EntryHolder(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorWithPathsTests.java b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorWithPathsTests.java index 5766b86b58..1354fbf39a 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorWithPathsTests.java +++ b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationDefinitionSourceEditorWithPathsTests.java @@ -135,11 +135,13 @@ public class FilterInvocationDefinitionSourceEditorWithPathsTests assertEquals(2, map.getMapSize()); } - public void testNoArgsConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = PathBasedFilterInvocationDefinitionMap.EntryHolder.class; + try { - new PathBasedFilterInvocationDefinitionMap().new EntryHolder(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java index d678a99a42..3ca684888c 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java +++ b/core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java @@ -77,11 +77,13 @@ public class FilterInvocationTests extends MockObjectTestCase { fi.getFullRequestUrl()); } - public void testNoArgsConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = FilterInvocation.class; + try { - new FilterInvocation(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/providers/cas/TicketResponseTests.java b/core/src/test/java/org/acegisecurity/providers/cas/TicketResponseTests.java index f7a9a49a43..dfca3bbd1b 100644 --- a/core/src/test/java/org/acegisecurity/providers/cas/TicketResponseTests.java +++ b/core/src/test/java/org/acegisecurity/providers/cas/TicketResponseTests.java @@ -82,11 +82,13 @@ public class TicketResponseTests extends TestCase { ticket.getProxyGrantingTicketIou()); } - public void testNoArgConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = TicketResponse.class; + try { - new TicketResponse(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } } diff --git a/core/src/test/java/org/acegisecurity/userdetails/UserTests.java b/core/src/test/java/org/acegisecurity/userdetails/UserTests.java index 32c5740244..5f268bd1fe 100644 --- a/core/src/test/java/org/acegisecurity/userdetails/UserTests.java +++ b/core/src/test/java/org/acegisecurity/userdetails/UserTests.java @@ -101,11 +101,13 @@ public class UserTests extends TestCase { new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE")}))); } - public void testNoArgConstructor() { + public void testNoArgConstructorDoesntExist() { + Class clazz = User.class; + try { - new User(); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + clazz.getDeclaredConstructor((Class[])null); + fail("Should have thrown NoSuchMethodException"); + } catch (NoSuchMethodException expected) { assertTrue(true); } }