@@ -93,22 +93,23 @@ private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
93
93
}
94
94
95
95
@ 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 ));
98
99
options .retainIncluded (errorAttributes );
99
100
return errorAttributes ;
100
101
}
101
102
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 <>();
104
105
errorAttributes .put ("timestamp" , new Date ());
105
106
addStatus (errorAttributes , webRequest );
106
107
addErrorDetails (errorAttributes , webRequest , includeStackTrace );
107
108
addPath (errorAttributes , webRequest );
108
109
return errorAttributes ;
109
110
}
110
111
111
- private void addStatus (Map <String , Object > errorAttributes , RequestAttributes requestAttributes ) {
112
+ private void addStatus (Map <String , @ Nullable Object > errorAttributes , RequestAttributes requestAttributes ) {
112
113
Integer status = getAttribute (requestAttributes , RequestDispatcher .ERROR_STATUS_CODE );
113
114
if (status == null ) {
114
115
errorAttributes .put ("status" , 999 );
@@ -125,7 +126,7 @@ private void addStatus(Map<String, Object> errorAttributes, RequestAttributes re
125
126
}
126
127
}
127
128
128
- private void addErrorDetails (Map <String , Object > errorAttributes , WebRequest webRequest ,
129
+ private void addErrorDetails (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
129
130
boolean includeStackTrace ) {
130
131
Throwable error = getError (webRequest );
131
132
if (error != null ) {
@@ -140,7 +141,7 @@ private void addErrorDetails(Map<String, Object> errorAttributes, WebRequest web
140
141
addErrorMessage (errorAttributes , webRequest , error );
141
142
}
142
143
143
- private void addErrorMessage (Map <String , Object > errorAttributes , WebRequest webRequest ,
144
+ private void addErrorMessage (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
144
145
@ Nullable Throwable error ) {
145
146
BindingResult bindingResult = extractBindingResult (error );
146
147
if (bindingResult != null ) {
@@ -155,20 +156,21 @@ private void addErrorMessage(Map<String, Object> errorAttributes, WebRequest web
155
156
addExceptionErrorMessage (errorAttributes , webRequest , error );
156
157
}
157
158
158
- private void addMessageAndErrorsFromBindingResult (Map <String , Object > errorAttributes , BindingResult result ) {
159
+ private void addMessageAndErrorsFromBindingResult (Map <String , @ Nullable Object > errorAttributes ,
160
+ BindingResult result ) {
159
161
errorAttributes .put ("message" , "Validation failed for object='%s'. Error count: %s"
160
162
.formatted (result .getObjectName (), result .getAllErrors ().size ()));
161
163
errorAttributes .put ("errors" , Error .wrapIfNecessary (result .getAllErrors ()));
162
164
}
163
165
164
- private void addMessageAndErrorsFromMethodValidationResult (Map <String , Object > errorAttributes ,
166
+ private void addMessageAndErrorsFromMethodValidationResult (Map <String , @ Nullable Object > errorAttributes ,
165
167
MethodValidationResult result ) {
166
168
errorAttributes .put ("message" , "Validation failed for method='%s'. Error count: %s"
167
169
.formatted (result .getMethod (), result .getAllErrors ().size ()));
168
170
errorAttributes .put ("errors" , Error .wrapIfNecessary (result .getAllErrors ()));
169
171
}
170
172
171
- private void addExceptionErrorMessage (Map <String , Object > errorAttributes , WebRequest webRequest ,
173
+ private void addExceptionErrorMessage (Map <String , @ Nullable Object > errorAttributes , WebRequest webRequest ,
172
174
@ Nullable Throwable error ) {
173
175
errorAttributes .put ("message" , getMessage (webRequest , error ));
174
176
}
@@ -211,14 +213,14 @@ protected String getMessage(WebRequest webRequest, @Nullable Throwable error) {
211
213
return null ;
212
214
}
213
215
214
- private void addStackTrace (Map <String , Object > errorAttributes , Throwable error ) {
216
+ private void addStackTrace (Map <String , @ Nullable Object > errorAttributes , Throwable error ) {
215
217
StringWriter stackTrace = new StringWriter ();
216
218
error .printStackTrace (new PrintWriter (stackTrace ));
217
219
stackTrace .flush ();
218
220
errorAttributes .put ("trace" , stackTrace .toString ());
219
221
}
220
222
221
- private void addPath (Map <String , Object > errorAttributes , RequestAttributes requestAttributes ) {
223
+ private void addPath (Map <String , @ Nullable Object > errorAttributes , RequestAttributes requestAttributes ) {
222
224
String path = getAttribute (requestAttributes , RequestDispatcher .ERROR_REQUEST_URI );
223
225
if (path != null ) {
224
226
errorAttributes .put ("path" , path );
0 commit comments