@@ -93,22 +93,23 @@ private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
9393 }
9494
9595 @ Override
96- public Map <String , Object > getErrorAttributes (WebRequest webRequest , ErrorAttributeOptions options ) {
97- Map <String , Object > errorAttributes = getErrorAttributes (webRequest , options .isIncluded (Include .STACK_TRACE ));
96+ public Map <String , @ Nullable Object > getErrorAttributes (WebRequest webRequest , ErrorAttributeOptions options ) {
97+ Map <String , @ Nullable Object > errorAttributes = getErrorAttributes (webRequest ,
98+ options .isIncluded (Include .STACK_TRACE ));
9899 options .retainIncluded (errorAttributes );
99100 return errorAttributes ;
100101 }
101102
102- private Map <String , Object > getErrorAttributes (WebRequest webRequest , boolean includeStackTrace ) {
103- Map <String , Object > errorAttributes = new LinkedHashMap <>();
103+ private Map <String , @ Nullable Object > getErrorAttributes (WebRequest webRequest , boolean includeStackTrace ) {
104+ Map <String , @ Nullable Object > errorAttributes = new LinkedHashMap <>();
104105 errorAttributes .put ("timestamp" , new Date ());
105106 addStatus (errorAttributes , webRequest );
106107 addErrorDetails (errorAttributes , webRequest , includeStackTrace );
107108 addPath (errorAttributes , webRequest );
108109 return errorAttributes ;
109110 }
110111
111- private void addStatus (Map <String , Object > errorAttributes , RequestAttributes requestAttributes ) {
112+ private void addStatus (Map <String , @ Nullable Object > errorAttributes , RequestAttributes requestAttributes ) {
112113 Integer status = getAttribute (requestAttributes , RequestDispatcher .ERROR_STATUS_CODE );
113114 if (status == null ) {
114115 errorAttributes .put ("status" , 999 );
@@ -125,7 +126,7 @@ private void addStatus(Map<String, Object> errorAttributes, RequestAttributes re
125126 }
126127 }
127128
128- private void addErrorDetails (Map <String , Object > errorAttributes , WebRequest webRequest ,
129+ private void addErrorDetails (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
129130 boolean includeStackTrace ) {
130131 Throwable error = getError (webRequest );
131132 if (error != null ) {
@@ -140,7 +141,7 @@ private void addErrorDetails(Map<String, Object> errorAttributes, WebRequest web
140141 addErrorMessage (errorAttributes , webRequest , error );
141142 }
142143
143- private void addErrorMessage (Map <String , Object > errorAttributes , WebRequest webRequest ,
144+ private void addErrorMessage (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
144145 @ Nullable Throwable error ) {
145146 BindingResult bindingResult = extractBindingResult (error );
146147 if (bindingResult != null ) {
@@ -155,20 +156,21 @@ private void addErrorMessage(Map<String, Object> errorAttributes, WebRequest web
155156 addExceptionErrorMessage (errorAttributes , webRequest , error );
156157 }
157158
158- private void addMessageAndErrorsFromBindingResult (Map <String , Object > errorAttributes , BindingResult result ) {
159+ private void addMessageAndErrorsFromBindingResult (Map <String , @ Nullable Object > errorAttributes ,
160+ BindingResult result ) {
159161 errorAttributes .put ("message" , "Validation failed for object='%s'. Error count: %s"
160162 .formatted (result .getObjectName (), result .getAllErrors ().size ()));
161163 errorAttributes .put ("errors" , Error .wrapIfNecessary (result .getAllErrors ()));
162164 }
163165
164- private void addMessageAndErrorsFromMethodValidationResult (Map <String , Object > errorAttributes ,
166+ private void addMessageAndErrorsFromMethodValidationResult (Map <String , @ Nullable Object > errorAttributes ,
165167 MethodValidationResult result ) {
166168 errorAttributes .put ("message" , "Validation failed for method='%s'. Error count: %s"
167169 .formatted (result .getMethod (), result .getAllErrors ().size ()));
168170 errorAttributes .put ("errors" , Error .wrapIfNecessary (result .getAllErrors ()));
169171 }
170172
171- private void addExceptionErrorMessage (Map <String , Object > errorAttributes , WebRequest webRequest ,
173+ private void addExceptionErrorMessage (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
172174 @ Nullable Throwable error ) {
173175 errorAttributes .put ("message" , getMessage (webRequest , error ));
174176 }
@@ -211,14 +213,14 @@ protected String getMessage(WebRequest webRequest, @Nullable Throwable error) {
211213 return null ;
212214 }
213215
214- private void addStackTrace (Map <String , Object > errorAttributes , Throwable error ) {
216+ private void addStackTrace (Map <String , @ Nullable Object > errorAttributes , Throwable error ) {
215217 StringWriter stackTrace = new StringWriter ();
216218 error .printStackTrace (new PrintWriter (stackTrace ));
217219 stackTrace .flush ();
218220 errorAttributes .put ("trace" , stackTrace .toString ());
219221 }
220222
221- private void addPath (Map <String , Object > errorAttributes , RequestAttributes requestAttributes ) {
223+ private void addPath (Map <String , @ Nullable Object > errorAttributes , RequestAttributes requestAttributes ) {
222224 String path = getAttribute (requestAttributes , RequestDispatcher .ERROR_REQUEST_URI );
223225 if (path != null ) {
224226 errorAttributes .put ("path" , path );
0 commit comments