File tree 4 files changed +31
-13
lines changed
src/main/java/com/fasterxml/jackson/core
4 files changed +31
-13
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ JSON library.
22
22
(contributed by valery1707 @github )
23
23
#587 : Add JsonGenerator #writeNumber (char [], int , int ) method
24
24
(contributed by Volkan Y )
25
+ #606 : Do not clear aggregated contents of `TextBuffer` when `releaseBuffers()` called
25
26
26
27
2.10 .4 (not yet released )
27
28
Original file line number Diff line number Diff line change @@ -219,7 +219,8 @@ protected void _closeInput() throws IOException {
219
219
* separately (if need be).
220
220
*/
221
221
@ Override
222
- protected void _releaseBuffers () throws IOException {
222
+ protected void _releaseBuffers () throws IOException
223
+ {
223
224
super ._releaseBuffers ();
224
225
// merge new symbols, if any
225
226
_symbols .release ();
@@ -287,15 +288,14 @@ protected boolean _loadMore() throws IOException
287
288
@ Override
288
289
public final String getText () throws IOException
289
290
{
290
- JsonToken t = _currToken ;
291
- if (t == JsonToken .VALUE_STRING ) {
291
+ if (_currToken == JsonToken .VALUE_STRING ) {
292
292
if (_tokenIncomplete ) {
293
293
_tokenIncomplete = false ;
294
294
_finishString (); // only strings can be incomplete
295
295
}
296
296
return _textBuffer .contentsAsString ();
297
297
}
298
- return _getText2 (t );
298
+ return _getText2 (_currToken );
299
299
}
300
300
301
301
@ Override // since 2.8
Original file line number Diff line number Diff line change @@ -274,8 +274,10 @@ protected void _releaseBuffers() throws IOException
274
274
if (buf != null ) {
275
275
// Let's not set it to null; this way should get slightly more meaningful
276
276
// error messages in case someone closes parser indirectly, without realizing.
277
- _inputBuffer = NO_BYTES ;
278
- _ioContext .releaseReadIOBuffer (buf );
277
+ if (buf != NO_BYTES ) {
278
+ _inputBuffer = NO_BYTES ;
279
+ _ioContext .releaseReadIOBuffer (buf );
280
+ }
279
281
}
280
282
}
281
283
}
Original file line number Diff line number Diff line change @@ -150,17 +150,31 @@ public static TextBuffer fromInitial(char[] initialSegment) {
150
150
* can still use this text buffer, it is not advisable to call this
151
151
* method if that is likely, since next time a buffer is needed,
152
152
* buffers need to reallocated.
153
- * Note: calling this method automatically also clears contents
154
- * of the buffer.
153
+ *<p>
154
+ * Note: since Jackson 2.11, calling this method will NOT clear already
155
+ * aggregated contents (that is, {@code _currentSegment}, to retain
156
+ * current token text if (but only if!) already aggregated.
155
157
*/
156
158
public void releaseBuffers ()
157
159
{
158
- if (_allocator == null ) {
159
- resetWithEmpty ();
160
- } else {
160
+ // inlined `resetWithEmpty()` (except leaving `_resultString` as-is
161
+ {
162
+ _inputStart = -1 ;
163
+ _currentSize = 0 ;
164
+ _inputLen = 0 ;
165
+
166
+ _inputBuffer = null ;
167
+ // note: _resultString retained (see https://github.com/FasterXML/jackson-databind/issues/2635
168
+ // for reason)
169
+ _resultArray = null ; // should this be retained too?
170
+
171
+ if (_hasSegments ) {
172
+ clearSegments ();
173
+ }
174
+ }
175
+
176
+ if (_allocator != null ) {
161
177
if (_currentSegment != null ) {
162
- // First, let's get rid of all but the largest char array
163
- resetWithEmpty ();
164
178
// And then return that array
165
179
char [] buf = _currentSegment ;
166
180
_currentSegment = null ;
@@ -428,6 +442,7 @@ public String contentsAsString()
428
442
}
429
443
}
430
444
}
445
+
431
446
return _resultString ;
432
447
}
433
448
You can’t perform that action at this time.
0 commit comments