Skip to content

Commit e51faad

Browse files
committed
#125 avoid nested JsonException
1 parent 40ca712 commit e51faad

8 files changed

+28
-0
lines changed

src/main/java/com/jsoniter/JsonIterator.java

+2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ public static void enableStreamingSupport() {
528528
isStreamingEnabled = true;
529529
try {
530530
DynamicCodegen.enableStreamingSupport();
531+
} catch (JsonException e) {
532+
throw e;
531533
} catch (Exception e) {
532534
throw new JsonException(e);
533535
}

src/main/java/com/jsoniter/ReflectionCollectionDecoder.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public ReflectionCollectionDecoder(Class clazz, Type[] typeArgs) {
2626
public Object decode(JsonIterator iter) throws IOException {
2727
try {
2828
return decode_(iter);
29+
} catch (JsonException e) {
30+
throw e;
2931
} catch (Exception e) {
3032
throw new JsonException(e);
3133
}

src/main/java/com/jsoniter/ReflectionMapDecoder.java

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public ReflectionMapDecoder(Class clazz, Type[] typeArgs) {
3333
public Object decode(JsonIterator iter) throws IOException {
3434
try {
3535
return decode_(iter);
36+
} catch (JsonException e) {
37+
throw e;
3638
} catch (Exception e) {
3739
throw new JsonException(e);
3840
}

src/main/java/com/jsoniter/ReflectionObjectDecoder.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public String toString() {
2727
public ReflectionObjectDecoder(ClassInfo classInfo) {
2828
try {
2929
init(classInfo);
30+
} catch (JsonException e) {
31+
throw e;
3032
} catch (Exception e) {
3133
throw new JsonException(e);
3234
}
@@ -115,6 +117,8 @@ public class OnlyField implements Decoder {
115117
public Object decode(JsonIterator iter) throws IOException {
116118
try {
117119
return decode_(iter);
120+
} catch (RuntimeException e) {
121+
throw e;
118122
} catch (Exception e) {
119123
throw new JsonException(e);
120124
}
@@ -178,6 +182,8 @@ public class WithCtor implements Decoder {
178182
public Object decode(JsonIterator iter) throws IOException {
179183
try {
180184
return decode_(iter);
185+
} catch (RuntimeException e) {
186+
throw e;
181187
} catch (Exception e) {
182188
throw new JsonException(e);
183189
}
@@ -255,6 +261,8 @@ public class WithWrapper implements Decoder {
255261
public Object decode(JsonIterator iter) throws IOException {
256262
try {
257263
return decode_(iter);
264+
} catch (RuntimeException e) {
265+
throw e;
258266
} catch (Exception e) {
259267
throw new JsonException(e);
260268
}

src/main/java/com/jsoniter/output/ReflectionObjectEncoder.java

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public ReflectionObjectEncoder(ClassInfo classInfo) {
3535
public void encode(Object obj, JsonStream stream) throws IOException {
3636
try {
3737
enocde_(obj, stream);
38+
} catch (RuntimeException e) {
39+
throw e;
3840
} catch (Exception e) {
3941
throw new JsonException(e);
4042
}
@@ -52,6 +54,8 @@ public Any wrap(Object obj) {
5254
Object val = getter.binding.method.invoke(obj);
5355
copied.put(getter.toName, val);
5456
}
57+
} catch (JsonException e) {
58+
throw e;
5559
} catch (Exception e) {
5660
throw new JsonException(e);
5761
}

src/main/java/com/jsoniter/spi/ClassDescriptor.java

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ private static Binding createBindingFromField(Map<String, Type> lookup, ClassInf
233233
binding.annotations = field.getAnnotations();
234234
binding.field = field;
235235
return binding;
236+
} catch (RuntimeException e) {
237+
throw e;
236238
} catch (Exception e) {
237239
throw new JsonException("failed to create binding for field: " + field, e);
238240
}
@@ -292,6 +294,8 @@ private static List<Binding> getSetters(Map<String, Type> lookup, ClassInfo clas
292294
setter.method = method;
293295
setter.annotations = method.getAnnotations();
294296
setters.add(setter);
297+
} catch (JsonException e) {
298+
throw e;
295299
} catch (Exception e) {
296300
throw new JsonException("failed to create binding from setter: " + method, e);
297301
}

src/main/java/com/jsoniter/spi/Config.java

+4
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,17 @@ private void updateBindingWithJsonProperty(Binding binding, JsonProperty jsonPro
461461
if (jsonProperty.decoder() != Decoder.class) {
462462
try {
463463
binding.decoder = jsonProperty.decoder().newInstance();
464+
} catch (RuntimeException e) {
465+
throw e;
464466
} catch (Exception e) {
465467
throw new JsonException(e);
466468
}
467469
}
468470
if (jsonProperty.encoder() != Encoder.class) {
469471
try {
470472
binding.encoder = jsonProperty.encoder().newInstance();
473+
} catch (JsonException e) {
474+
throw e;
471475
} catch (Exception e) {
472476
throw new JsonException(e);
473477
}

src/main/java/com/jsoniter/spi/TypeLiteral.java

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ private static String generateCacheKey(Type type, String prefix) {
110110
decoderClassName.append('_');
111111
decoderClassName.append(typeName);
112112
}
113+
} catch (JsonException e) {
114+
throw e;
113115
} catch (Exception e) {
114116
throw new JsonException("failed to generate cache key for: " + type, e);
115117
}

0 commit comments

Comments
 (0)