From a70a907e2ad4f49c4807b1914e69b97f7573561e Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Fri, 29 Sep 2023 15:29:55 +0100 Subject: Fix Sonar Issues for clamp/acm Issue-ID: POLICY-4834 Change-Id: I4489dc66e9b20c8264ec88593f0b5d89d62f1ef8 Signed-off-by: FrancescoFioraEst --- .../acm/runtime/main/web/RuntimeErrorController.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'runtime-acm/src/main') diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java index f7feba32c..a7faf049d 100755 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021,2023 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -30,7 +30,6 @@ import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.boot.web.servlet.error.ErrorController; @@ -49,9 +48,6 @@ public class RuntimeErrorController implements ErrorController { private final ErrorAttributes errorAttributes; - @Value("${server.error.path}") - private String path; - /** * Constructor. * @@ -62,7 +58,7 @@ public class RuntimeErrorController implements ErrorController { } protected HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + var statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); if (statusCode == null) { return HttpStatus.INTERNAL_SERVER_ERROR; } @@ -80,25 +76,25 @@ public class RuntimeErrorController implements ErrorController { * @param request HttpServletRequest * @return ResponseEntity */ + @SuppressWarnings("squid:S3752") @RequestMapping(value = "${server.error.path}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> handleError(HttpServletRequest request) { Map map = this.errorAttributes.getErrorAttributes(new ServletWebRequest(request), ErrorAttributeOptions.defaults()); var sb = new StringBuilder(); - final Object error = map.get("error"); + final var error = map.get("error"); if (error != null) { - sb.append(error.toString()).append(" "); + sb.append(error).append(" "); } - final Object message = map.get("message"); + final var message = map.get("message"); if (message != null) { - sb.append(message.toString()); + sb.append(message); } TypedSimpleResponse resp = new TypedSimpleResponse<>(); resp.setErrorDetails(sb.toString()); return ResponseEntity.status(getStatus(request)).body(resp); - } } -- cgit 1.2.3-korg