Skip to content

Commit 86b4276

Browse files
committed
fix(dependency): Issue with kork-web while upgrading spring-boot to 2.5.14
While upgrading the spring-boot, the compilation of kork-web module failed with following error: ``` > Task :kork-web:compileGroovy FAILED /kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/controllers/GenericErrorController.java:41: error: incompatible types: Boolean cannot be converted to ErrorAttributeOptions errorAttributes.getErrorAttributes(webRequest, includeStackTrace); ^ ``` ``` /kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/controllers/GenericErrorController.java:51: error: method does not override or implement a method from a supertype @OverRide ^ ``` ``` > Task :kork-web:compileGroovy /kork/kork-web/src/main/java/com/netflix/spinnaker/kork/web/selector/v2/SelectableService.java uses unchecked or unsafe operations. startup failed: /kork/kork-web/src/main/groovy/com/netflix/spinnaker/config/ErrorConfiguration.groovy: 37: Method 'getErrorAttributes' from class 'com.netflix.spinnaker.config.ErrorConfiguration$1' does not override method from its superclass or interfaces but is annotated with @OverRide. @ line 37, column 7. @OverRide ^ ``` The root cause is the deprecation of following methods in Spring boot 2.3.x and now removal of code from spring boot 2.5.x: ErrorAttributes.getErrorAttributes(ServerRequest, boolean) spring-projects/spring-boot@158933c spring-projects/spring-boot#21324 ErrorController.getErrorPath() spring-projects/spring-boot#19844 Fixed the issue with required code changes.
1 parent 9c425bf commit 86b4276

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

kork-web/src/main/groovy/com/netflix/spinnaker/config/ErrorConfiguration.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.netflix.spinnaker.kork.web.exceptions.ExceptionMessageDecorator
2222
import com.netflix.spinnaker.kork.web.exceptions.ExceptionSummaryService
2323
import com.netflix.spinnaker.kork.web.exceptions.GenericExceptionHandlers
2424
import org.springframework.beans.factory.ObjectProvider
25+
import org.springframework.boot.web.error.ErrorAttributeOptions
2526
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes
2627
import org.springframework.boot.web.servlet.error.ErrorAttributes
2728
import org.springframework.context.annotation.Bean
@@ -35,10 +36,10 @@ class ErrorConfiguration {
3536
final DefaultErrorAttributes defaultErrorAttributes = new DefaultErrorAttributes()
3637
return new ErrorAttributes() {
3738
@Override
38-
Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
39+
Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions includeStackTrace) {
3940
// By default, Spring echoes back the user's requested path. This opens up a potential XSS vulnerability where a
4041
// user, for example, requests "GET /<script>alert('Hi')</script> HTTP/1.1".
41-
Map<String, Object> errorAttributes = defaultErrorAttributes.getErrorAttributes(webRequest, includeStackTrace)
42+
Map<String, Object> errorAttributes = defaultErrorAttributes.getErrorAttributes(webRequest, includeStackTrace.getIncludes().contains(ErrorAttributeOptions.Include.STACK_TRACE))
4243
errorAttributes.remove("path")
4344
return errorAttributes
4445
}

kork-web/src/main/java/com/netflix/spinnaker/kork/web/controllers/GenericErrorController.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes;
2020
import java.util.Map;
21+
import org.springframework.boot.web.error.ErrorAttributeOptions;
2122
import org.springframework.boot.web.servlet.error.ErrorAttributes;
2223
import org.springframework.boot.web.servlet.error.ErrorController;
2324
import org.springframework.web.bind.annotation.RequestMapping;
@@ -33,12 +34,15 @@ public GenericErrorController(ErrorAttributes errorAttributes) {
3334
this.errorAttributes = errorAttributes;
3435
}
3536

36-
@RequestMapping(value = "/error")
37+
@RequestMapping(value = "${server.error.path:/error}")
3738
public Map error(
3839
@RequestParam(value = "trace", defaultValue = "false") Boolean includeStackTrace,
3940
WebRequest webRequest) {
40-
Map<String, Object> attributes =
41-
errorAttributes.getErrorAttributes(webRequest, includeStackTrace);
41+
ErrorAttributeOptions options =
42+
includeStackTrace
43+
? ErrorAttributeOptions.defaults().including(ErrorAttributeOptions.Include.STACK_TRACE)
44+
: ErrorAttributeOptions.defaults();
45+
Map<String, Object> attributes = errorAttributes.getErrorAttributes(webRequest, options);
4246

4347
Throwable exception = errorAttributes.getError(webRequest);
4448
if (exception != null && exception instanceof HasAdditionalAttributes) {
@@ -47,9 +51,4 @@ public Map error(
4751

4852
return attributes;
4953
}
50-
51-
@Override
52-
public String getErrorPath() {
53-
return "/error";
54-
}
5554
}

0 commit comments

Comments
 (0)