Skip to content

Commit 5448e5e

Browse files
committed
Minor improvement to handling of JsonGenerator.close() on exception case
1 parent 03a49b1 commit 5448e5e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
import java.util.concurrent.atomic.AtomicReference;
1010

1111
import com.fasterxml.jackson.annotation.*;
12-
1312
import com.fasterxml.jackson.core.*;
1413
import com.fasterxml.jackson.core.io.CharacterEscapes;
1514
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
1615
import com.fasterxml.jackson.core.type.ResolvedType;
1716
import com.fasterxml.jackson.core.type.TypeReference;
1817
import com.fasterxml.jackson.core.util.*;
19-
2018
import com.fasterxml.jackson.databind.cfg.BaseSettings;
2119
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
2220
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
@@ -2838,6 +2836,10 @@ protected final void _configAndWriteValue(JsonGenerator jgen, Object value)
28382836
* will not mask exception that is pending)
28392837
*/
28402838
if (!closed) {
2839+
/* 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
2840+
* structures, which typically causes more damage.
2841+
*/
2842+
jgen.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
28412843
try {
28422844
jgen.close();
28432845
} catch (IOException ioe) { }
@@ -2869,6 +2871,9 @@ protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Clas
28692871
jgen.close();
28702872
} finally {
28712873
if (!closed) {
2874+
// 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
2875+
// structures, which typically causes more damage.
2876+
jgen.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
28722877
try {
28732878
jgen.close();
28742879
} catch (IOException ioe) { }
@@ -2897,6 +2902,9 @@ private final void _configAndWriteCloseable(JsonGenerator jgen, Object value, Se
28972902
* been closed
28982903
*/
28992904
if (jgen != null) {
2905+
// 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
2906+
// structures, which typically causes more damage.
2907+
jgen.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
29002908
try {
29012909
jgen.close();
29022910
} catch (IOException ioe) { }

src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,7 @@ protected void _verifySchemaType(FormatSchema schema)
774774
* Method called to configure the generator as necessary and then
775775
* call write functionality
776776
*/
777-
protected final void _configAndWriteValue(JsonGenerator jgen, Object value)
778-
throws IOException, JsonGenerationException, JsonMappingException
777+
protected final void _configAndWriteValue(JsonGenerator jgen, Object value) throws IOException
779778
{
780779
_configureJsonGenerator(jgen);
781780
// [JACKSON-282]: consider Closeable
@@ -797,6 +796,10 @@ protected final void _configAndWriteValue(JsonGenerator jgen, Object value)
797796
* will not mask exception that is pending)
798797
*/
799798
if (!closed) {
799+
/* 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
800+
* structures, which typically causes more damage.
801+
*/
802+
jgen.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
800803
try {
801804
jgen.close();
802805
} catch (IOException ioe) { }
@@ -829,6 +832,10 @@ private final void _writeCloseable(JsonGenerator jgen, Object value, Serializati
829832
* been closed
830833
*/
831834
if (jgen != null) {
835+
/* 04-Mar-2014, tatu: But! Let's try to prevent auto-closing of
836+
* structures, which typically causes more damage.
837+
*/
838+
jgen.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
832839
try {
833840
jgen.close();
834841
} catch (IOException ioe) { }

0 commit comments

Comments
 (0)