From bdf97cb2f81d260d9eff46f5630015f14c3deb4a Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 31 Aug 2023 15:20:58 -0700 Subject: [PATCH] Fix #1097 (move IOContext down to ParserMinimalBase) --- .../tools/jackson/core/base/ParserBase.java | 13 +++---- .../jackson/core/base/ParserMinimalBase.java | 36 +++++++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/tools/jackson/core/base/ParserBase.java b/src/main/java/tools/jackson/core/base/ParserBase.java index 62cc1e61b6..fdc6454ced 100644 --- a/src/main/java/tools/jackson/core/base/ParserBase.java +++ b/src/main/java/tools/jackson/core/base/ParserBase.java @@ -30,12 +30,6 @@ public abstract class ParserBase extends ParserMinimalBase /********************************************************************** */ - /** - * I/O context for this reader. It handles buffer allocation - * for the reader. - */ - protected final IOContext _ioContext; - /** * Flag that indicates whether parser is closed or not. Gets * set when parser is either closed by explicit call @@ -212,7 +206,6 @@ public abstract class ParserBase extends ParserMinimalBase protected ParserBase(ObjectReadContext readCtxt, IOContext ctxt, int streamReadFeatures) { super(readCtxt, ctxt, streamReadFeatures); - _ioContext = ctxt; _textBuffer = ctxt.constructReadConstrainedTextBuffer(); } @@ -281,8 +274,11 @@ public Object currentValue() { } */ - @Override public void close() throws JacksonException { + @Override + public void close() throws JacksonException + { if (!_closed) { + super.close(); // will close IOContext (bit early but still) // 19-Jan-2018, tatu: as per [core#440] need to ensure no more data assumed available _inputPtr = Math.max(_inputPtr, _inputEnd); _closed = true; @@ -294,7 +290,6 @@ public Object currentValue() { // as per [JACKSON-324], do in finally block // Also, internal buffer(s) can now be released as well _releaseBuffers(); - _ioContext.close(); } } } diff --git a/src/main/java/tools/jackson/core/base/ParserMinimalBase.java b/src/main/java/tools/jackson/core/base/ParserMinimalBase.java index ce871994b3..a26f9780f4 100644 --- a/src/main/java/tools/jackson/core/base/ParserMinimalBase.java +++ b/src/main/java/tools/jackson/core/base/ParserMinimalBase.java @@ -143,7 +143,7 @@ public abstract class ParserMinimalBase extends JsonParser * {@link tools.jackson.core.StreamReadFeature}s * are enabled. */ - protected int _streamReadFeatures; + protected final int _streamReadFeatures; /** * Constraints to use for this parser. @@ -166,6 +166,14 @@ public abstract class ParserMinimalBase extends JsonParser */ protected final ObjectReadContext _objectReadContext; + /** + * I/O context for this reader. It handles buffer allocation + * for the reader, including possible reuse/recycling. + * + * @since 3.0 (at this level) + */ + protected final IOContext _ioContext; + /** * Last token retrieved via {@link #nextToken}, if any. * Null before the first call to nextToken(), @@ -185,30 +193,24 @@ public abstract class ParserMinimalBase extends JsonParser /********************************************************************** */ + // 31-Aug-2023, tatu: To be removed ASAP + /* protected ParserMinimalBase(ObjectReadContext readCtxt) { super(); _objectReadContext = readCtxt; _streamReadFeatures = readCtxt.getStreamReadFeatures(STREAM_READ_FEATURE_DEFAULTS); _streamReadConstraints = readCtxt.streamReadConstraints(); } - - @Deprecated // Not to be used in 3.0? - protected ParserMinimalBase(ObjectReadContext readCtxt, - int streamReadFeatures) - { - super(); - _objectReadContext = readCtxt; - _streamReadFeatures = streamReadFeatures; - _streamReadConstraints = readCtxt.streamReadConstraints(); - } + */ protected ParserMinimalBase(ObjectReadContext readCtxt, - IOContext ctxt, int streamReadFeatures) + IOContext ioCtxt, int streamReadFeatures) { super(); _objectReadContext = readCtxt; + _ioContext = ioCtxt; _streamReadFeatures = streamReadFeatures; - _streamReadConstraints = ctxt.streamReadConstraints(); + _streamReadConstraints = ioCtxt.streamReadConstraints(); } /* @@ -266,7 +268,13 @@ public StreamReadConstraints streamReadConstraints() { // public JsonToken getCurrentToken() // public boolean hasCurrentToken() - // public abstract void close(); + @Override + public void close() throws JacksonException + { + // !!! TODO: calls to closeInput(), releaseBuffers() + _ioContext.close(); + } + // public abstract boolean isClosed(); /*