Skip to content

Commit b28fd13

Browse files
authored
close IOContext (#605)
1 parent 1320f00 commit b28fd13

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ public void close() throws IOException
518518
// Also, internal buffer(s) can now be released as well
519519
_releaseBuffers();
520520
}
521+
_ioContext.close();
521522
}
522523
}
523524

src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ private Feature(boolean defaultState) {
138138
* Stax2 API: this is problematic if trying to use {@link #writeRaw} calls.
139139
*/
140140
protected final boolean _stax2Emulation;
141-
142-
protected final IOContext _ioContext;
143141

144142
/**
145143
* @since 2.16
@@ -227,9 +225,8 @@ private Feature(boolean defaultState) {
227225
public ToXmlGenerator(IOContext ctxt, int stdFeatures, int xmlFeatures,
228226
ObjectCodec codec, XMLStreamWriter sw, XmlNameProcessor nameProcessor)
229227
{
230-
super(stdFeatures, codec);
228+
super(stdFeatures, codec, ctxt);
231229
_formatFeatures = xmlFeatures;
232-
_ioContext = ctxt;
233230
_streamWriteConstraints = ctxt.streamWriteConstraints();
234231
_originalXmlWriter = sw;
235232
_xmlWriter = Stax2WriterAdapter.wrapIfNecessary(sw);
@@ -1332,42 +1329,43 @@ public void flush() throws IOException
13321329
@Override
13331330
public void close() throws IOException
13341331
{
1335-
// boolean wasClosed = _closed;
1336-
super.close();
1337-
1338-
// First: let's see that we still have buffers...
1339-
if (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)) {
1340-
try {
1341-
while (true) {
1342-
/* 28-May-2016, tatu: To work around incompatibility introduced by
1343-
* `jackson-core` 2.8 where return type of `getOutputContext()`
1344-
* changed, let's do direct access here.
1345-
*/
1332+
if (!isClosed()) {
1333+
1334+
// First: let's see that we still have buffers...
1335+
if (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)) {
1336+
try {
1337+
while (true) {
1338+
/* 28-May-2016, tatu: To work around incompatibility introduced by
1339+
* `jackson-core` 2.8 where return type of `getOutputContext()`
1340+
* changed, let's do direct access here.
1341+
*/
13461342
// JsonStreamContext ctxt = getOutputContext();
1347-
JsonStreamContext ctxt = _writeContext;
1348-
if (ctxt.inArray()) {
1349-
writeEndArray();
1350-
} else if (ctxt.inObject()) {
1351-
writeEndObject();
1352-
} else {
1353-
break;
1343+
JsonStreamContext ctxt = _writeContext;
1344+
if (ctxt.inArray()) {
1345+
writeEndArray();
1346+
} else if (ctxt.inObject()) {
1347+
writeEndObject();
1348+
} else {
1349+
break;
1350+
}
13541351
}
1352+
} catch (ArrayIndexOutOfBoundsException e) {
1353+
/* 29-Nov-2010, tatu: Stupid, stupid SJSXP doesn't do array checks, so we get
1354+
* hit by this as a collateral problem in some cases. Yuck.
1355+
*/
1356+
throw new JsonGenerationException(e, this);
13551357
}
1356-
} catch (ArrayIndexOutOfBoundsException e) {
1357-
/* 29-Nov-2010, tatu: Stupid, stupid SJSXP doesn't do array checks, so we get
1358-
* hit by this as a collateral problem in some cases. Yuck.
1359-
*/
1360-
throw new JsonGenerationException(e, this);
13611358
}
1362-
}
1363-
try {
1364-
if (_ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) {
1365-
_xmlWriter.closeCompletely();
1366-
} else {
1367-
_xmlWriter.close();
1359+
try {
1360+
if (_ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) {
1361+
_xmlWriter.closeCompletely();
1362+
} else {
1363+
_xmlWriter.close();
1364+
}
1365+
} catch (XMLStreamException e) {
1366+
StaxUtil.throwAsGenerationException(e, this);
13681367
}
1369-
} catch (XMLStreamException e) {
1370-
StaxUtil.throwAsGenerationException(e, this);
1368+
super.close();
13711369
}
13721370
}
13731371

0 commit comments

Comments
 (0)