1
0
mirror of synced 2026-08-05 17:57:15 +00:00

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
@@ -156,7 +156,7 @@ public class OAuth2AuthorizationCodeGrantFilter extends OncePerRequestFilter {
}
private void processAuthorizationResponse(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws IOException {
OAuth2AuthorizationRequest authorizationRequest =
this.authorizationRequestRepository.removeAuthorizationRequest(request, response);
@@ -190,7 +190,7 @@ public class OAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFilt
}
private void sendRedirectForAuthorization(HttpServletRequest request, HttpServletResponse response,
OAuth2AuthorizationRequest authorizationRequest) throws IOException, ServletException {
OAuth2AuthorizationRequest authorizationRequest) throws IOException {
if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(authorizationRequest.getGrantType())) {
this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, request, response);
@@ -199,7 +199,7 @@ public class OAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFilt
}
private void unsuccessfulRedirectForAuthorization(HttpServletRequest request, HttpServletResponse response,
Exception failed) throws IOException, ServletException {
Exception failed) throws IOException {
if (logger.isErrorEnabled()) {
logger.error("Authorization Request failed: " + failed.toString(), failed);
@@ -150,7 +150,7 @@ public class OAuth2LoginAuthenticationFilter extends AbstractAuthenticationProce
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
throws AuthenticationException {
MultiValueMap<String, String> params = OAuth2AuthorizationResponseUtils.toMultiMap(request.getParameterMap());
if (!OAuth2AuthorizationResponseUtils.isAuthorizationResponse(params)) {
@@ -126,7 +126,7 @@ public final class OAuth2AuthorizedClientArgumentResolver implements HandlerMeth
public Object resolveArgument(MethodParameter parameter,
@Nullable ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
@Nullable WebDataBinderFactory binderFactory) throws Exception {
@Nullable WebDataBinderFactory binderFactory) {
String clientRegistrationId = this.resolveClientRegistrationId(parameter);
if (StringUtils.isEmpty(clientRegistrationId)) {
@@ -173,12 +173,12 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction
}
@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Hooks.onLastOperator(REQUEST_CONTEXT_OPERATOR_KEY, Operators.lift((s, sub) -> createRequestContextSubscriber(sub)));
}
@Override
public void destroy() throws Exception {
public void destroy() {
Hooks.resetOnLastOperator(REQUEST_CONTEXT_OPERATOR_KEY);
}
@@ -77,7 +77,7 @@ public class OAuth2LoginAuthenticationProviderTests {
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
public void setUp() {
this.clientRegistration = clientRegistration().build();
this.authorizationRequest = request().scope("scope1", "scope2").build();
this.authorizationResponse = success().build();
@@ -57,7 +57,7 @@ public class NimbusAuthorizationCodeTokenResponseClientTests {
public ExpectedException exception = ExpectedException.none();
@Before
public void setUp() throws Exception {
public void setUp() {
this.clientRegistrationBuilder = clientRegistration()
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC);
this.authorizationRequest = request().build();
@@ -107,7 +107,7 @@ public class NimbusAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenRedirectUriMalformedThenThrowIllegalArgumentException() throws Exception {
public void getTokenResponseWhenRedirectUriMalformedThenThrowIllegalArgumentException() {
this.exception.expect(IllegalArgumentException.class);
String redirectUri = "http:\\example.com";
@@ -121,7 +121,7 @@ public class NimbusAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenTokenUriMalformedThenThrowIllegalArgumentException() throws Exception {
public void getTokenResponseWhenTokenUriMalformedThenThrowIllegalArgumentException() {
this.exception.expect(IllegalArgumentException.class);
String tokenUri = "http:\\provider.com\\oauth2\\token";
@@ -166,7 +166,7 @@ public class NimbusAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenTokenUriInvalidThenThrowOAuth2AuthorizationException() throws Exception {
public void getTokenResponseWhenTokenUriInvalidThenThrowOAuth2AuthorizationException() {
this.exception.expect(OAuth2AuthorizationException.class);
String tokenUri = "https://invalid-provider.com/oauth2/token";
@@ -170,7 +170,7 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClientTests {
// }
//
@Test
public void getTokenResponseWhenErrorResponseThenThrowOAuth2AuthorizationException() throws Exception {
public void getTokenResponseWhenErrorResponseThenThrowOAuth2AuthorizationException() {
String accessTokenErrorResponse = "{\n" +
" \"error\": \"unauthorized_client\"\n" +
"}\n";
@@ -184,7 +184,7 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClientTests {
// gh-5594
@Test
public void getTokenResponseWhenServerErrorResponseThenThrowOAuth2AuthorizationException() throws Exception {
public void getTokenResponseWhenServerErrorResponseThenThrowOAuth2AuthorizationException() {
String accessTokenErrorResponse = "{}";
this.server.enqueue(jsonResponse(accessTokenErrorResponse).setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()));
@@ -194,7 +194,7 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenSuccessResponseAndNotBearerTokenTypeThenThrowOAuth2AuthorizationException() throws Exception {
public void getTokenResponseWhenSuccessResponseAndNotBearerTokenTypeThenThrowOAuth2AuthorizationException() {
String accessTokenSuccessResponse = "{\n" +
" \"access_token\": \"access-token-1234\",\n" +
" \"token_type\": \"not-bearer\",\n" +
@@ -209,7 +209,7 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenSuccessResponseIncludesScopeThenReturnAccessTokenResponseUsingResponseScope() throws Exception {
public void getTokenResponseWhenSuccessResponseIncludesScopeThenReturnAccessTokenResponseUsingResponseScope() {
String accessTokenSuccessResponse = "{\n" +
" \"access_token\": \"access-token-1234\",\n" +
" \"token_type\": \"bearer\",\n" +
@@ -226,7 +226,7 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClientTests {
}
@Test
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenReturnAccessTokenResponseUsingRequestedScope() throws Exception {
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenReturnAccessTokenResponseUsingRequestedScope() {
String accessTokenSuccessResponse = "{\n" +
" \"access_token\": \"access-token-1234\",\n" +
" \"token_type\": \"bearer\",\n" +
@@ -241,10 +241,9 @@ public class ClientRegistrationsTest {
/**
* We currently only support authorization_code, so verify we have a meaningful error until we add support.
* @throws Exception
*/
@Test
public void issuerWhenGrantTypesSupportedInvalidThenException() throws Exception {
public void issuerWhenGrantTypesSupportedInvalidThenException() {
this.response.put("grant_types_supported", Arrays.asList("implicit"));
assertThatThrownBy(() -> registration(""))
@@ -253,7 +252,7 @@ public class ClientRegistrationsTest {
}
@Test
public void issuerWhenOAuth2GrantTypesSupportedInvalidThenException() throws Exception {
public void issuerWhenOAuth2GrantTypesSupportedInvalidThenException() {
this.response.put("grant_types_supported", Arrays.asList("implicit"));
assertThatThrownBy(() -> registrationOAuth2("", null))
@@ -317,10 +316,9 @@ public class ClientRegistrationsTest {
/**
* We currently only support client_secret_basic, so verify we have a meaningful error until we add support.
* @throws Exception
*/
@Test
public void issuerWhenTokenEndpointAuthMethodsInvalidThenException() throws Exception {
public void issuerWhenTokenEndpointAuthMethodsInvalidThenException() {
this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("tls_client_auth"));
assertThatThrownBy(() -> registration(""))
@@ -329,7 +327,7 @@ public class ClientRegistrationsTest {
}
@Test
public void issuerWhenOAuth2TokenEndpointAuthMethodsInvalidThenException() throws Exception {
public void issuerWhenOAuth2TokenEndpointAuthMethodsInvalidThenException() {
this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("tls_client_auth"));
assertThatThrownBy(() -> registrationOAuth2("", null))
@@ -395,7 +393,7 @@ public class ClientRegistrationsTest {
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
public MockResponse dispatch(RecordedRequest request) {
switch(request.getPath()) {
case "/.well-known/oauth-authorization-server/issuer1":
case "/.well-known/oauth-authorization-server/":
@@ -433,7 +431,7 @@ public class ClientRegistrationsTest {
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
public MockResponse dispatch(RecordedRequest request) {
switch(request.getPath()) {
case "/issuer1/.well-known/openid-configuration":
case "/.well-known/openid-configuration/":
@@ -104,7 +104,7 @@ public class DefaultReactiveOAuth2UserServiceTests {
}
@Test
public void loadUserWhenUserInfoSuccessResponseThenReturnUser() throws Exception {
public void loadUserWhenUserInfoSuccessResponseThenReturnUser() {
String userInfoResponse = "{\n" +
" \"id\": \"user1\",\n" +
" \"first-name\": \"first\",\n" +
@@ -179,7 +179,7 @@ public class DefaultReactiveOAuth2UserServiceTests {
}
@Test
public void loadUserWhenUserInfoSuccessResponseInvalidThenThrowOAuth2AuthenticationException() throws Exception {
public void loadUserWhenUserInfoSuccessResponseInvalidThenThrowOAuth2AuthenticationException() {
String userInfoResponse = "{\n" +
" \"id\": \"user1\",\n" +
" \"first-name\": \"first\",\n" +
@@ -196,7 +196,7 @@ public class DefaultReactiveOAuth2UserServiceTests {
}
@Test
public void loadUserWhenUserInfoErrorResponseThenThrowOAuth2AuthenticationException() throws Exception {
public void loadUserWhenUserInfoErrorResponseThenThrowOAuth2AuthenticationException() {
this.server.enqueue(new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setResponseCode(500).setBody("{}"));
assertThatThrownBy(() -> this.userService.loadUser(oauth2UserRequest()).block())
@@ -205,7 +205,7 @@ public class DefaultReactiveOAuth2UserServiceTests {
}
@Test
public void loadUserWhenUserInfoUriInvalidThenThrowAuthenticationServiceException() throws Exception {
public void loadUserWhenUserInfoUriInvalidThenThrowAuthenticationServiceException() {
this.clientRegistration.userInfoUri("https://invalid-provider.com/user");
assertThatThrownBy(() -> this.userService.loadUser(oauth2UserRequest()).block())
.isInstanceOf(AuthenticationServiceException.class);
@@ -575,7 +575,7 @@ public class ServletOAuth2AuthorizedClientExchangeFilterFunctionTests {
}
@Test
public void filterWhenRequestAttributesNotSetAndHooksNotInitThenDefaultsNotAvailable() throws Exception {
public void filterWhenRequestAttributesNotSetAndHooksNotInitThenDefaultsNotAvailable() {
// this.function.afterPropertiesSet(); // Hooks.onLastOperator() NOT initialized
this.function.setDefaultOAuth2AuthorizedClient(true);
@@ -79,7 +79,7 @@ public class OAuth2AccessTokenResponseHttpMessageConverter extends AbstractHttpM
@Override
protected OAuth2AccessTokenResponse readInternal(Class<? extends OAuth2AccessTokenResponse> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
throws HttpMessageNotReadableException {
try {
@SuppressWarnings("unchecked")
@@ -94,7 +94,7 @@ public class OAuth2AccessTokenResponseHttpMessageConverter extends AbstractHttpM
@Override
protected void writeInternal(OAuth2AccessTokenResponse tokenResponse, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
throws HttpMessageNotWritableException {
try {
Map<String, String> tokenResponseParameters = this.tokenResponseParametersConverter.convert(tokenResponse);
@@ -67,7 +67,7 @@ public class OAuth2ErrorHttpMessageConverter extends AbstractHttpMessageConverte
@Override
protected OAuth2Error readInternal(Class<? extends OAuth2Error> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
throws HttpMessageNotReadableException {
try {
@SuppressWarnings("unchecked")
@@ -82,7 +82,7 @@ public class OAuth2ErrorHttpMessageConverter extends AbstractHttpMessageConverte
@Override
protected void writeInternal(OAuth2Error oauth2Error, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
throws HttpMessageNotWritableException {
try {
Map<String, String> errorParameters = this.errorParametersConverter.convert(oauth2Error);
@@ -97,7 +97,7 @@ public class OAuth2BodyExtractorsTests {
}
@Test
public void oauth2AccessTokenResponseWhenValidThenCreated() throws Exception {
public void oauth2AccessTokenResponseWhenValidThenCreated() {
BodyExtractor<Mono<OAuth2AccessTokenResponse>, ReactiveHttpInputMessage> extractor = OAuth2BodyExtractors
.oauth2AccessTokenResponse();
@@ -124,7 +124,7 @@ public class OAuth2BodyExtractorsTests {
@Test
// gh-6087
public void oauth2AccessTokenResponseWhenMultipleAttributeTypesThenCreated() throws Exception {
public void oauth2AccessTokenResponseWhenMultipleAttributeTypesThenCreated() {
BodyExtractor<Mono<OAuth2AccessTokenResponse>, ReactiveHttpInputMessage> extractor = OAuth2BodyExtractors
.oauth2AccessTokenResponse();
@@ -89,7 +89,7 @@ public class MappedJwtClaimSetConverterTests {
}
@Test
public void convertWhenUsingDefaultsThenCoercesAllAttributesInJwtSpec() throws Exception {
public void convertWhenUsingDefaultsThenCoercesAllAttributesInJwtSpec() {
MappedJwtClaimSetConverter converter =
MappedJwtClaimSetConverter.withDefaults(Collections.emptyMap());
@@ -114,7 +114,7 @@ public class MappedJwtClaimSetConverterTests {
}
@Test
public void convertWhenUsingCustomConverterThenAllOtherDefaultsAreStillUsed() throws Exception {
public void convertWhenUsingCustomConverterThenAllOtherDefaultsAreStillUsed() {
Converter<Object, String> claimConverter = mock(Converter.class);
MappedJwtClaimSetConverter converter = MappedJwtClaimSetConverter
.withDefaults(Collections.singletonMap(JwtClaimNames.SUB, claimConverter));
@@ -97,7 +97,7 @@ public class NimbusJwtDecoderJwkSupportTests {
// gh-5168
@Test
public void decodeWhenExpClaimNullThenDoesNotThrowException() throws Exception {
public void decodeWhenExpClaimNullThenDoesNotThrowException() {
NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(JWK_SET_URL);
jwtDecoder.setRestOperations(mockJwkSetResponse(JWK_SET));
jwtDecoder.setClaimSetConverter(map -> {
@@ -442,7 +442,7 @@ public class NimbusJwtDecoderTests {
private static class MockJwtProcessor extends DefaultJWTProcessor<SecurityContext> {
@Override
public JWTClaimsSet process(SignedJWT signedJWT, SecurityContext context)
throws BadJOSEException, JOSEException {
throws BadJOSEException {
try {
return signedJWT.getJWTClaimsSet();
@@ -61,8 +61,7 @@ public final class BearerTokenAuthenticationEntryPoint implements Authentication
@Override
public void commence(
HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException)
throws IOException, ServletException {
AuthenticationException authException) {
HttpStatus status = HttpStatus.UNAUTHORIZED;
@@ -59,8 +59,7 @@ public final class BearerTokenAccessDeniedHandler implements AccessDeniedHandler
@Override
public void handle(
HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException)
throws IOException, ServletException {
AccessDeniedException accessDeniedException) {
Map<String, String> parameters = new LinkedHashMap<>();