9
9
import com .fasterxml .jackson .annotation .JsonInclude ;
10
10
import com .fasterxml .jackson .core .*;
11
11
import com .fasterxml .jackson .core .JsonParser .NumberType ;
12
+ import com .fasterxml .jackson .core .exc .WrappedIOException ;
12
13
import com .fasterxml .jackson .databind .*;
13
14
import com .fasterxml .jackson .databind .annotation .JacksonStdImpl ;
14
15
import com .fasterxml .jackson .databind .introspect .AnnotatedMember ;
@@ -234,29 +235,30 @@ protected void visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeH
234
235
* Rules for wrapping and unwrapping are bit complicated; essentially:
235
236
*<ul>
236
237
* <li>Errors are to be passed as is (if uncovered via unwrapping)
237
- * <li>"Plain" IOExceptions (ones that are not of type
238
- * {@link JsonMappingException} are to be passed as is
238
+ * <li>Wrapped {@code IOException}s are unpeeled
239
239
*</ul>
240
240
*/
241
241
public void wrapAndThrow (SerializerProvider provider ,
242
242
Throwable t , Object bean , String fieldName )
243
243
throws JacksonException
244
244
{
245
- /* 05-Mar-2009, tatu: But one nasty edge is when we get
246
- * StackOverflow: usually due to infinite loop. But that
247
- * usually gets hidden within an InvocationTargetException...
248
- */
245
+ // 05-Mar-2009, tatu: But one nasty edge is when we get
246
+ // StackOverflow: usually due to infinite loop. But that
247
+ // usually gets hidden within an InvocationTargetException...
249
248
while (t instanceof InvocationTargetException && t .getCause () != null ) {
250
249
t = t .getCause ();
251
250
}
252
- // Errors and "plain" to be passed as is
251
+ // 16-Jan-2021, tatu: Let's peel off useless wrapper as well
252
+ while (t instanceof WrappedIOException && t .getCause () != null ) {
253
+ t = t .getCause ();
254
+ }
255
+ // Errors to be passed as is, most others not
253
256
ClassUtil .throwIfError (t );
254
- // Ditto for IOExceptions... except for mapping exceptions!
255
- boolean wrap = (provider == null ) || provider .isEnabled (SerializationFeature .WRAP_EXCEPTIONS );
256
- if (t instanceof JacksonException ) {
257
- throw (JacksonException ) t ;
258
- } else if (!wrap ) {
259
- ClassUtil .throwIfRTE (t );
257
+ if (!(t instanceof JacksonException )) {
258
+ boolean wrap = (provider == null ) || provider .isEnabled (SerializationFeature .WRAP_EXCEPTIONS );
259
+ if (!wrap ) {
260
+ ClassUtil .throwIfRTE (t );
261
+ }
260
262
}
261
263
// Need to add reference information
262
264
throw JsonMappingException .wrapWithPath (t , bean , fieldName );
@@ -269,14 +271,16 @@ public void wrapAndThrow(SerializerProvider provider,
269
271
while (t instanceof InvocationTargetException && t .getCause () != null ) {
270
272
t = t .getCause ();
271
273
}
272
- // Errors are to be passed as is
274
+ while (t instanceof WrappedIOException && t .getCause () != null ) {
275
+ t = t .getCause ();
276
+ }
277
+ // Errors to be passed as is, most others not
273
278
ClassUtil .throwIfError (t );
274
- // Ditto for IOExceptions... except for mapping exceptions!
275
- boolean wrap = (provider == null ) || provider .isEnabled (SerializationFeature .WRAP_EXCEPTIONS );
276
- if (t instanceof JacksonException ) {
277
- throw (JacksonException ) t ;
278
- } else if (!wrap ) {
279
- ClassUtil .throwIfRTE (t );
279
+ if (!(t instanceof JacksonException )) {
280
+ boolean wrap = (provider == null ) || provider .isEnabled (SerializationFeature .WRAP_EXCEPTIONS );
281
+ if (!wrap ) {
282
+ ClassUtil .throwIfRTE (t );
283
+ }
280
284
}
281
285
// Need to add reference information
282
286
throw JsonMappingException .wrapWithPath (t , bean , index );
0 commit comments