@@ -138,8 +138,6 @@ private Feature(boolean defaultState) {
138
138
* Stax2 API: this is problematic if trying to use {@link #writeRaw} calls.
139
139
*/
140
140
protected final boolean _stax2Emulation ;
141
-
142
- protected final IOContext _ioContext ;
143
141
144
142
/**
145
143
* @since 2.16
@@ -227,9 +225,8 @@ private Feature(boolean defaultState) {
227
225
public ToXmlGenerator (IOContext ctxt , int stdFeatures , int xmlFeatures ,
228
226
ObjectCodec codec , XMLStreamWriter sw , XmlNameProcessor nameProcessor )
229
227
{
230
- super (stdFeatures , codec );
228
+ super (stdFeatures , codec , ctxt );
231
229
_formatFeatures = xmlFeatures ;
232
- _ioContext = ctxt ;
233
230
_streamWriteConstraints = ctxt .streamWriteConstraints ();
234
231
_originalXmlWriter = sw ;
235
232
_xmlWriter = Stax2WriterAdapter .wrapIfNecessary (sw );
@@ -1332,42 +1329,43 @@ public void flush() throws IOException
1332
1329
@ Override
1333
1330
public void close () throws IOException
1334
1331
{
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
+ */
1346
1342
// 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
+ }
1354
1351
}
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 );
1355
1357
}
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 );
1361
1358
}
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 );
1368
1367
}
1369
- } catch (XMLStreamException e ) {
1370
- StaxUtil .throwAsGenerationException (e , this );
1368
+ super .close ();
1371
1369
}
1372
1370
}
1373
1371
0 commit comments