Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar: Local-Variable Type Inference should be used #11983

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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