Skip to content

Commit e9b3277

Browse files
committed
Minor change to StackOverflowError re-throwing, trying to avoid triggering of SOE due to local call depth
1 parent 60274f0 commit e9b3277

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,11 @@ protected void serializeFields(Object bean, JsonGenerator gen, SerializerProvide
689689
* have many stack frames to spare... just one or two; can't
690690
* make many calls.
691691
*/
692-
JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
693-
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
692+
// 10-Dec-2015, tatu: and due to above, avoid "from" method, call ctor directly:
693+
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
694+
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
695+
696+
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
694697
mapE.prependPath(new JsonMappingException.Reference(bean, name));
695698
throw mapE;
696699
}
@@ -735,7 +738,9 @@ protected void serializeFieldsFiltered(Object bean, JsonGenerator gen,
735738
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
736739
wrapAndThrow(provider, e, bean, name);
737740
} catch (StackOverflowError e) {
738-
JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
741+
// Minimize call depth since we are close to fail:
742+
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
743+
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
739744
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
740745
mapE.prependPath(new JsonMappingException.Reference(bean, name));
741746
throw mapE;

0 commit comments

Comments
 (0)