Remove redundant throws clauses

Removes exceptions that are declared in a method's signature but never thrown by the method itself or its implementations/derivatives.
This commit is contained in:
Lars Grefer
2019-08-23 01:03:54 +02:00
parent f0515a021c
commit 34dd5fea30
418 changed files with 1146 additions and 1273 deletions

View File

@@ -39,7 +39,7 @@ public class HelloWebfluxMethodApplicationITests {
@Test
public void messageWhenNotAuthenticated() throws Exception {
public void messageWhenNotAuthenticated() {
this.rest
.get()
.uri("/message")
@@ -48,7 +48,7 @@ public class HelloWebfluxMethodApplicationITests {
}
@Test
public void messageWhenUserThenForbidden() throws Exception {
public void messageWhenUserThenForbidden() {
this.rest
.get()
.uri("/message")
@@ -58,7 +58,7 @@ public class HelloWebfluxMethodApplicationITests {
}
@Test
public void messageWhenAdminThenOk() throws Exception {
public void messageWhenAdminThenOk() {
this.rest
.get()
.uri("/message")

View File

@@ -36,7 +36,7 @@ import static org.springframework.security.config.Customizer.withDefaults;
public class SecurityConfig {
@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
return http
// Demonstrate that method security works
// Best practice to use both for defense in depth

View File

@@ -50,7 +50,7 @@ public class HelloWebfluxMethodApplicationTests {
}
@Test
public void messageWhenNotAuthenticated() throws Exception {
public void messageWhenNotAuthenticated() {
this.rest
.get()
.uri("/message")
@@ -61,7 +61,7 @@ public class HelloWebfluxMethodApplicationTests {
// --- Basic Authentication ---
@Test
public void messageWhenUserThenForbidden() throws Exception {
public void messageWhenUserThenForbidden() {
this.rest
.get()
.uri("/message")
@@ -71,7 +71,7 @@ public class HelloWebfluxMethodApplicationTests {
}
@Test
public void messageWhenAdminThenOk() throws Exception {
public void messageWhenAdminThenOk() {
this.rest
.get()
.uri("/message")
@@ -85,7 +85,7 @@ public class HelloWebfluxMethodApplicationTests {
@Test
@WithMockUser
public void messageWhenWithMockUserThenForbidden() throws Exception {
public void messageWhenWithMockUserThenForbidden() {
this.rest
.get()
.uri("/message")
@@ -95,7 +95,7 @@ public class HelloWebfluxMethodApplicationTests {
@Test
@WithMockUser(roles = "ADMIN")
public void messageWhenWithMockAdminThenOk() throws Exception {
public void messageWhenWithMockAdminThenOk() {
this.rest
.get()
.uri("/message")
@@ -107,7 +107,7 @@ public class HelloWebfluxMethodApplicationTests {
// --- mutateWith mockUser ---
@Test
public void messageWhenMutateWithMockUserThenForbidden() throws Exception {
public void messageWhenMutateWithMockUserThenForbidden() {
this.rest
.mutateWith(mockUser())
.get()
@@ -117,7 +117,7 @@ public class HelloWebfluxMethodApplicationTests {
}
@Test
public void messageWhenMutateWithMockAdminThenOk() throws Exception {
public void messageWhenMutateWithMockAdminThenOk() {
this.rest
.mutateWith(mockUser().roles("ADMIN"))
.get()

View File

@@ -37,7 +37,7 @@ public class HelloWebfluxApplicationITests {
WebTestClient rest;
@Test
public void basicWhenNoCredentialsThenUnauthorized() throws Exception {
public void basicWhenNoCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -46,7 +46,7 @@ public class HelloWebfluxApplicationITests {
}
@Test
public void basicWhenValidCredentialsThenOk() throws Exception {
public void basicWhenValidCredentialsThenOk() {
this.rest
.get()
.uri("/")
@@ -57,7 +57,7 @@ public class HelloWebfluxApplicationITests {
}
@Test
public void basicWhenInvalidCredentialsThenUnauthorized() throws Exception {
public void basicWhenInvalidCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")

View File

@@ -51,7 +51,7 @@ public class HelloWebfluxApplicationTests {
}
@Test
public void basicWhenNoCredentialsThenUnauthorized() throws Exception {
public void basicWhenNoCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -60,7 +60,7 @@ public class HelloWebfluxApplicationTests {
}
@Test
public void basicWhenValidCredentialsThenOk() throws Exception {
public void basicWhenValidCredentialsThenOk() {
this.rest
.get()
.uri("/")
@@ -71,7 +71,7 @@ public class HelloWebfluxApplicationTests {
}
@Test
public void basicWhenInvalidCredentialsThenUnauthorized() throws Exception {
public void basicWhenInvalidCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -82,7 +82,7 @@ public class HelloWebfluxApplicationTests {
}
@Test
public void mockSupportWhenMutateWithMockUserThenOk() throws Exception {
public void mockSupportWhenMutateWithMockUserThenOk() {
this.rest
.mutateWith(mockUser())
.get()
@@ -94,7 +94,7 @@ public class HelloWebfluxApplicationTests {
@Test
@WithMockUser
public void mockSupportWhenWithMockUserThenOk() throws Exception {
public void mockSupportWhenWithMockUserThenOk() {
this.rest
.get()
.uri("/")

View File

@@ -43,7 +43,7 @@ public class HelloWebfluxFnApplicationITests {
}
@Test
public void basicWhenNoCredentialsThenUnauthorized() throws Exception {
public void basicWhenNoCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -52,7 +52,7 @@ public class HelloWebfluxFnApplicationITests {
}
@Test
public void basicWhenValidCredentialsThenOk() throws Exception {
public void basicWhenValidCredentialsThenOk() {
this.rest
.get()
.uri("/")
@@ -63,7 +63,7 @@ public class HelloWebfluxFnApplicationITests {
}
@Test
public void basicWhenInvalidCredentialsThenUnauthorized() throws Exception {
public void basicWhenInvalidCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")

View File

@@ -52,7 +52,7 @@ public class HelloWebfluxFnApplicationTests {
}
@Test
public void basicWhenNoCredentialsThenUnauthorized() throws Exception {
public void basicWhenNoCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -61,7 +61,7 @@ public class HelloWebfluxFnApplicationTests {
}
@Test
public void basicWhenValidCredentialsThenOk() throws Exception {
public void basicWhenValidCredentialsThenOk() {
this.rest
.get()
.uri("/")
@@ -72,7 +72,7 @@ public class HelloWebfluxFnApplicationTests {
}
@Test
public void basicWhenInvalidCredentialsThenUnauthorized() throws Exception {
public void basicWhenInvalidCredentialsThenUnauthorized() {
this.rest
.get()
.uri("/")
@@ -83,7 +83,7 @@ public class HelloWebfluxFnApplicationTests {
}
@Test
public void mockSupportWhenMutateWithMockUserThenOk() throws Exception {
public void mockSupportWhenMutateWithMockUserThenOk() {
this.rest
.mutateWith(mockUser())
.get()
@@ -95,7 +95,7 @@ public class HelloWebfluxFnApplicationTests {
@Test
@WithMockUser
public void mockSupportWhenWithMockUserThenOk() throws Exception {
public void mockSupportWhenWithMockUserThenOk() {
this.rest
.get()
.uri("/")

View File

@@ -116,7 +116,7 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
// @formatter:off
endpoints
.authenticationManager(this.authenticationManager)

View File

@@ -291,7 +291,7 @@ public class OAuth2LoginApplicationTests {
assertThat(errorElement.asText()).contains("invalid_redirect_uri_parameter");
}
private void assertLoginPage(HtmlPage page) throws Exception {
private void assertLoginPage(HtmlPage page) {
assertThat(page.getTitleText()).isEqualTo("Please sign in");
int expectedClients = 4;
@@ -322,7 +322,7 @@ public class OAuth2LoginApplicationTests {
}
}
private void assertIndexPage(HtmlPage page) throws Exception {
private void assertIndexPage(HtmlPage page) {
assertThat(page.getTitleText()).isEqualTo("Spring Security - OAuth 2.0 Login");
DomNodeList<HtmlElement> divElements = page.getBody().getElementsByTagName("div");

View File

@@ -94,7 +94,7 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
private void intializeMockWebServer(MockWebServer mockWebServer) {
Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
public MockResponse dispatch(RecordedRequest request) {
if ("/.well-known/jwks.json".equals(request.getPath())) {
return JWKS_RESPONSE;
}

View File

@@ -93,7 +93,7 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
private void intializeMockWebServer(MockWebServer mockWebServer) {
Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
public MockResponse dispatch(RecordedRequest request) {
if ("/.well-known/jwks.json".equals(request.getPath())) {
return JWKS_RESPONSE;
}

View File

@@ -32,7 +32,7 @@ import static org.springframework.security.config.Customizer.withDefaults;
public class SecurityConfig {
@Bean
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http
.authorizeExchange(exchanges ->
exchanges

View File

@@ -93,7 +93,7 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
private void intializeMockWebServer(MockWebServer mockWebServer) {
Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
public MockResponse dispatch(RecordedRequest request) {
if ("/.well-known/jwks.json".equals(request.getPath())) {
return JWKS_RESPONSE;
}

View File

@@ -32,7 +32,7 @@ import static org.springframework.security.config.Customizer.withDefaults;
public class SecurityConfig {
@Bean
SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
SecurityWebFilterChain configure(ServerHttpSecurity http) {
http
.authorizeExchange(exchanges ->
exchanges

View File

@@ -47,7 +47,7 @@ public class WebfluxFormApplicationTests {
}
@Test
public void loginWhenInvalidUsernameThenError() throws Exception {
public void loginWhenInvalidUsernameThenError() {
LoginPage login = IndexPage.to(this.driver, this.port, LoginPage.class);
login.assertAt();
@@ -60,7 +60,7 @@ public class WebfluxFormApplicationTests {
}
@Test
public void loginAndLogout() throws Exception {
public void loginAndLogout() {
LoginPage login = IndexPage.to(this.driver, this.port, LoginPage.class);
login.assertAt();

View File

@@ -49,46 +49,46 @@ public class AspectJInterceptorTests {
private SecuredService securedService;
@Test
public void publicMethod() throws Exception {
public void publicMethod() {
service.publicMethod();
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void securedMethodNotAuthenticated() throws Exception {
public void securedMethodNotAuthenticated() {
service.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void securedMethodWrongRole() throws Exception {
public void securedMethodWrongRole() {
SecurityContextHolder.getContext().setAuthentication(admin);
service.secureMethod();
}
@Test
public void securedMethodEverythingOk() throws Exception {
public void securedMethodEverythingOk() {
SecurityContextHolder.getContext().setAuthentication(user);
service.secureMethod();
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void securedClassNotAuthenticated() throws Exception {
public void securedClassNotAuthenticated() {
securedService.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void securedClassWrongRole() throws Exception {
public void securedClassWrongRole() {
SecurityContextHolder.getContext().setAuthentication(admin);
securedService.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void securedClassWrongRoleOnNewedInstance() throws Exception {
public void securedClassWrongRoleOnNewedInstance() {
SecurityContextHolder.getContext().setAuthentication(admin);
new SecuredService().secureMethod();
}
@Test
public void securedClassEverythingOk() throws Exception {
public void securedClassEverythingOk() {
SecurityContextHolder.getContext().setAuthentication(user);
securedService.secureMethod();
new SecuredService().secureMethod();

View File

@@ -27,7 +27,7 @@ public class SecurityConfig {
// @formatter:off
@Bean
public UserDetailsService userDetailsService() throws Exception {
public UserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build();
return new InMemoryUserDetailsManager(user);
}

View File

@@ -27,11 +27,11 @@ public class SecurityConfig {
// @formatter:off
@Bean
public UserDetailsService userDetailsService() throws Exception {
public UserDetailsService userDetailsService() {
User.UserBuilder builder = User.withDefaultPasswordEncoder();
UserDetails user = builder.username("user").password("password").roles("USER").build();
UserDetails admin = builder.username("admin").password("password").roles("USER", "ADMIN").build();
return new InMemoryUserDetailsManager(user, admin);
}
// @formatter:on
}
}

View File

@@ -43,46 +43,46 @@ public class AspectJInterceptorTests {
private SecuredService securedService;
@Test
public void testPublicMethod() throws Exception {
public void testPublicMethod() {
service.publicMethod();
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void testSecuredMethodNotAuthenticated() throws Exception {
public void testSecuredMethodNotAuthenticated() {
service.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void testSecuredMethodWrongRole() throws Exception {
public void testSecuredMethodWrongRole() {
SecurityContextHolder.getContext().setAuthentication(admin);
service.secureMethod();
}
@Test
public void testSecuredMethodEverythingOk() throws Exception {
public void testSecuredMethodEverythingOk() {
SecurityContextHolder.getContext().setAuthentication(user);
service.secureMethod();
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void testSecuredClassNotAuthenticated() throws Exception {
public void testSecuredClassNotAuthenticated() {
securedService.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void testSecuredClassWrongRole() throws Exception {
public void testSecuredClassWrongRole() {
SecurityContextHolder.getContext().setAuthentication(admin);
securedService.secureMethod();
}
@Test(expected = AccessDeniedException.class)
public void testSecuredClassWrongRoleOnNewedInstance() throws Exception {
public void testSecuredClassWrongRoleOnNewedInstance() {
SecurityContextHolder.getContext().setAuthentication(admin);
new SecuredService().secureMethod();
}
@Test
public void testSecuredClassEverythingOk() throws Exception {
public void testSecuredClassEverythingOk() {
SecurityContextHolder.getContext().setAuthentication(user);
securedService.secureMethod();
new SecuredService().secureMethod();

View File

@@ -45,7 +45,7 @@ public final class ProxyTicketSampleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws IOException {
// NOTE: The CasAuthenticationToken can also be obtained using
// SecurityContextHolder.getContext().getAuthentication()
final CasAuthenticationToken token = (CasAuthenticationToken) request

View File

@@ -59,7 +59,7 @@ public class ContactManagerBackend extends ApplicationObjectSupport implements
// ~ Methods
// ========================================================================================================
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Assert.notNull(contactDao, "contactDao required");
Assert.notNull(mutableAclService, "mutableAclService required");
}

View File

@@ -63,7 +63,7 @@ public class DataSourcePopulator implements InitializingBean {
// ~ Methods
// ========================================================================================================
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Assert.notNull(mutableAclService, "mutableAclService required");
Assert.notNull(template, "dataSource required");
Assert.notNull(tt, "platformTransactionManager required");

View File

@@ -45,7 +45,7 @@ public class DataSourcePopulator implements InitializingBean {
this.documentDao = documentDao;
}
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
// ACL tables
template.execute("CREATE TABLE ACL_SID(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,PRINCIPAL BOOLEAN NOT NULL,SID VARCHAR_IGNORECASE(100) NOT NULL,CONSTRAINT UNIQUE_UK_1 UNIQUE(SID,PRINCIPAL));");
template.execute("CREATE TABLE ACL_CLASS(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,CLASS VARCHAR_IGNORECASE(100) NOT NULL,CLASS_ID_TYPE VARCHAR_IGNORECASE(100),CONSTRAINT UNIQUE_UK_2 UNIQUE(CLASS));");

View File

@@ -120,7 +120,7 @@ public class GaeAuthenticationFilter extends GenericFilterBean {
}
@Override
public void afterPropertiesSet() throws ServletException {
public void afterPropertiesSet() {
Assert.notNull(authenticationManager, "AuthenticationManager must be set");
}

View File

@@ -30,7 +30,7 @@ import com.google.appengine.api.users.UserServiceFactory;
public class GoogleAccountsAuthenticationEntryPoint implements AuthenticationEntryPoint {
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
AuthenticationException authException) throws IOException {
UserService userService = UserServiceFactory.getUserService();
response.sendRedirect(userService.createLoginURL(request.getRequestURI()));

View File

@@ -34,7 +34,7 @@ public class AppRoleTests {
}
@Test
public void bitsAreCorrect() throws Exception {
public void bitsAreCorrect() {
// If this fails, someone has modified the Enum and the Datastore is probably
// corrupt!
assertThat(ADMIN.getBit()).isZero();

View File

@@ -35,12 +35,12 @@ public class GaeDataStoreUserRegistryTests {
new LocalDatastoreServiceTestConfig());
@Before
public void setUp() throws Exception {
public void setUp() {
helper.setUp();
}
@After
public void tearDown() throws Exception {
public void tearDown() {
helper.tearDown();
}

View File

@@ -45,12 +45,12 @@ public class UsernameEqualsPasswordLoginModule implements LoginModule {
// ========================================================================================================
@Override
public boolean abort() throws LoginException {
public boolean abort() {
return true;
}
@Override
public boolean commit() throws LoginException {
public boolean commit() {
return true;
}
@@ -87,7 +87,7 @@ public class UsernameEqualsPasswordLoginModule implements LoginModule {
}
@Override
public boolean logout() throws LoginException {
public boolean logout() {
return true;
}

View File

@@ -102,12 +102,10 @@ public class ServletApiController {
* @param loginForm
* @param result
* @return
* @throws ServletException
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response,
@ModelAttribute LoginForm loginForm, BindingResult result)
throws ServletException {
@ModelAttribute LoginForm loginForm, BindingResult result) {
try {
request.login(loginForm.getUsername(), loginForm.getPassword());
}

View File

@@ -21,7 +21,7 @@ import org.springframework.util.Assert;
public class SeedData implements InitializingBean {
private BankDao bankDao;
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Assert.notNull(bankDao, "bankDao cannot be null");
bankDao.createOrUpdateAccount(new Account("rod"));
bankDao.createOrUpdateAccount(new Account("dianne"));

View File

@@ -34,7 +34,7 @@ public class ListAccounts implements Controller {
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
HttpServletResponse response) {
// Security check (this is unnecessary if Spring Security is performing the
// authorization)
// if (request.getUserPrincipal() == null) {