Skip to content

Commit

Permalink
Merge pull request #11983 from qmonmert/varinstead
Browse files Browse the repository at this point in the history
Sonar: Local-Variable Type Inference should be used
  • Loading branch information
murdos authored Feb 24, 2025
2 parents 54fd46d + b9152a1 commit b14846f
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AssertionErrorsHandler(@Qualifier("assertionErrorMessageSource") MessageS
@ExceptionHandler(AssertionException.class)
ProblemDetail handleAssertionError(AssertionException exception) {
HttpStatus status = buildStatus(exception);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
var problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));

problem.setTitle(getMessage(exception.type(), "title"));
problem.setProperty("key", exception.type().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BeanValidationErrorsHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
ProblemDetail handleMethodArgumentNotValid(MethodArgumentNotValidException exception) {
ProblemDetail problem = buildProblemDetail();
var problem = buildProblemDetail();
problem.setProperty(ERRORS, buildErrors(exception));

log.info(exception.getMessage(), exception);
Expand All @@ -43,7 +43,7 @@ private Map<String, String> buildErrors(MethodArgumentNotValidException exceptio

@ExceptionHandler(ConstraintViolationException.class)
ProblemDetail handleConstraintViolationException(ConstraintViolationException exception) {
ProblemDetail problem = buildProblemDetail();
var problem = buildProblemDetail();
problem.setProperty(ERRORS, buildErrors(exception));

log.info(exception.getMessage(), exception);
Expand All @@ -52,10 +52,7 @@ ProblemDetail handleConstraintViolationException(ConstraintViolationException ex
}

private ProblemDetail buildProblemDetail() {
ProblemDetail problem = ProblemDetail.forStatusAndDetail(
HttpStatus.BAD_REQUEST,
"One or more fields were invalid. See 'errors' for details."
);
var problem = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "One or more fields were invalid. See 'errors' for details.");

problem.setTitle("Bean validation error");
return problem;
Expand All @@ -70,7 +67,7 @@ private Map<String, String> buildErrors(ConstraintViolationException exception)

private Function<ConstraintViolation<?>, String> toFieldName() {
return error -> {
String propertyPath = error.getPropertyPath().toString();
var propertyPath = error.getPropertyPath().toString();

return propertyPath.substring(propertyPath.lastIndexOf('.') + 1);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GeneratorErrorsHandler(@Qualifier("generatorErrorMessageSource") MessageS
@ExceptionHandler(GeneratorException.class)
ProblemDetail handleGeneratorException(GeneratorException exception) {
HttpStatus status = Optional.ofNullable(Enums.map(exception.status(), HttpStatus.class)).orElse(HttpStatus.INTERNAL_SERVER_ERROR);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
var problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));

problem.setTitle(getMessage(exception.key(), "title"));
problem.setProperty("key", exception.key().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CorsFilterConfiguration(CorsConfiguration corsConfiguration) {

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
var source = new UrlBasedCorsConfigurationSource();
if (
!CollectionUtils.isEmpty(corsConfiguration.getAllowedOrigins()) ||
!CollectionUtils.isEmpty(corsConfiguration.getAllowedOriginPatterns())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class {{ baseName }}ErrorsHandler {
@ExceptionHandler({{ baseName }}Exception.class)
ProblemDetail handle{{ baseName }}Exception({{ baseName }}Exception exception) {
HttpStatus status = Optional.ofNullable(Enums.map(exception.status(), HttpStatus.class)).orElse(HttpStatus.INTERNAL_SERVER_ERROR);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
var problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
problem.setTitle(getMessage(exception.key(), "title"));
problem.setProperty("key", exception.key().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AssertionErrorsHandler {
@ExceptionHandler(AssertionException.class)
ProblemDetail handleAssertionError(AssertionException exception) {
HttpStatus status = buildStatus(exception);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
var problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
problem.setTitle(getMessage(exception.type(), "title"));
problem.setProperty("key", exception.type().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AuthenticationExceptionAdvice {
@ExceptionHandler(NotAuthenticatedUserException.class)
public ProblemDetail handleNotAuthenticateUser(NotAuthenticatedUserException ex) {
ProblemDetail detail = ProblemDetail.forStatus(HttpStatus.UNAUTHORIZED);
var detail = ProblemDetail.forStatus(HttpStatus.UNAUTHORIZED);
detail.setTitle("not authenticated");
detail.setProperty(MESSAGE_KEY, "error.http.401");
Expand All @@ -26,7 +26,7 @@ class AuthenticationExceptionAdvice {

@ExceptionHandler(UnknownAuthenticationException.class)
public ProblemDetail handleUnknownAuthentication(UnknownAuthenticationException ex) {
ProblemDetail detail = ProblemDetail.forStatus(HttpStatus.INTERNAL_SERVER_ERROR);
var detail = ProblemDetail.forStatus(HttpStatus.INTERNAL_SERVER_ERROR);
detail.setTitle("unknown authentication");
detail.setProperty(MESSAGE_KEY, "error.http.500");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JwtReader implements AuthenticationTokenReader {
}

private Optional<Authentication> parseToken(String token) {
Claims claims = parser.parseSignedClaims(token).getPayload();
var claims = parser.parseSignedClaims(token).getPayload();
List<SimpleGrantedAuthority> authorities = readAuthorities(claims);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AuthenticationResource {
public ResponseEntity<RestToken> authorize(@Valid @RequestBody RestAuthenticationQuery authenticationQuery) {
Token token = authenticator.authenticate(authenticationQuery);
HttpHeaders httpHeaders = new HttpHeaders();
var httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.AUTHORIZATION, token.bearer());
return new ResponseEntity<>(RestToken.from(token), httpHeaders, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BeanValidationErrorsHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
ProblemDetail handleMethodArgumentNotValid(MethodArgumentNotValidException exception) {
ProblemDetail problem = buildProblemDetail();
var problem = buildProblemDetail();
problem.setProperty(ERRORS, buildErrors(exception));
log.info(exception.getMessage(), exception);
Expand All @@ -43,7 +43,7 @@ class BeanValidationErrorsHandler {

@ExceptionHandler(ConstraintViolationException.class)
ProblemDetail handleConstraintViolationException(ConstraintViolationException exception) {
ProblemDetail problem = buildProblemDetail();
var problem = buildProblemDetail();
problem.setProperty(ERRORS, buildErrors(exception));
log.info(exception.getMessage(), exception);
Expand All @@ -52,7 +52,7 @@ class BeanValidationErrorsHandler {
}

private ProblemDetail buildProblemDetail() {
ProblemDetail problem = ProblemDetail.forStatusAndDetail(
var problem = ProblemDetail.forStatusAndDetail(
HttpStatus.BAD_REQUEST,
"One or more fields were invalid. See 'errors' for details."
);
Expand All @@ -70,7 +70,7 @@ class BeanValidationErrorsHandler {

private Function<ConstraintViolation<?>, String> toFieldName() {
return error -> {
String propertyPath = error.getPropertyPath().toString();
var propertyPath = error.getPropertyPath().toString();
return propertyPath.substring(propertyPath.lastIndexOf(".") + 1);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CorsFilterConfiguration {

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
var source = new UrlBasedCorsConfigurationSource();
if (
!CollectionUtils.isEmpty(corsConfiguration.getAllowedOrigins()) ||
!CollectionUtils.isEmpty(corsConfiguration.getAllowedOriginPatterns())
Expand Down

0 comments on commit b14846f

Please sign in to comment.