Skip to content

Commit 1000b22

Browse files
committed
Merge branch '2.10' into 2.11
2 parents a057a37 + 18819b1 commit 1000b22

File tree

5 files changed

+91
-12
lines changed

5 files changed

+91
-12
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ David Nault (dnault@github)
196196
(2.10.0)
197197

198198
Fabien Renaud (fabienrenaud@github)
199-
* Reported, contributed fix fir #533: UTF-8 BOM not accounted for in
199+
* Reported, contributed fix for #533: UTF-8 BOM not accounted for in
200200
`JsonLocation.getByteOffset()`
201201
(2.10.0)
202+
* Reported, contributed fix for #603: 'JsonParser.getCurrentLocation()`
203+
byte/char offset update incorrectly for big payloads
204+
(2.10.3)
202205

203206
Todd O'Bryan (toddobryan@github)
204207
* Contributed fix fox #455: Jackson reports wrong locations for JsonEOFException

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ JSON library.
2727

2828
#592: DataFormatMatcher#getMatchedFormatName throws NPE when no match exists
2929
(reported by Scott L)
30+
#603: 'JsonParser.getCurrentLocation()` byte/char offset update incorrectly for big payloads
31+
(reported, fix contributed by Fabien R)
3032

3133
2.10.2 (05-Jan-2020)
3234

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,10 @@ protected void _loadMoreGuaranteed() throws IOException {
245245

246246
protected boolean _loadMore() throws IOException
247247
{
248-
final int bufSize = _inputEnd;
249-
250248
if (_reader != null) {
251249
int count = _reader.read(_inputBuffer, 0, _inputBuffer.length);
252250
if (count > 0) {
253-
_inputPtr = 0;
254-
_inputEnd = count;
255-
251+
final int bufSize = _inputEnd;
256252
_currInputProcessed += bufSize;
257253
_currInputRowStart -= bufSize;
258254

@@ -261,6 +257,9 @@ protected boolean _loadMore() throws IOException
261257
// in negative value, which is fine as combine value remains unchanged.
262258
_nameStartOffset -= bufSize;
263259

260+
_inputPtr = 0;
261+
_inputEnd = count;
262+
264263
return true;
265264
}
266265
// End of input

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public Object getInputSource() {
211211

212212
protected final boolean _loadMore() throws IOException
213213
{
214-
final int bufSize = _inputEnd;
215214
if (_inputStream != null) {
216215
int space = _inputBuffer.length;
217216
if (space == 0) { // only occurs when we've been closed
@@ -220,17 +219,19 @@ protected final boolean _loadMore() throws IOException
220219

221220
int count = _inputStream.read(_inputBuffer, 0, space);
222221
if (count > 0) {
223-
_inputPtr = 0;
224-
_inputEnd = count;
222+
final int bufSize = _inputEnd;
225223

226-
_currInputProcessed += _inputEnd;
227-
_currInputRowStart -= _inputEnd;
224+
_currInputProcessed += bufSize;
225+
_currInputRowStart -= bufSize;
228226

229227
// 26-Nov-2015, tatu: Since name-offset requires it too, must offset
230228
// this increase to avoid "moving" name-offset, resulting most likely
231229
// in negative value, which is fine as combine value remains unchanged.
232230
_nameStartOffset -= bufSize;
233231

232+
_inputPtr = 0;
233+
_inputEnd = count;
234+
234235
return true;
235236
}
236237
// End of input

src/test/java/com/fasterxml/jackson/core/read/LocationOffsetsTest.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.fasterxml.jackson.core.*;
44

5+
import java.io.IOException;
6+
import java.util.Random;
7+
58
public class LocationOffsetsTest extends com.fasterxml.jackson.core.BaseTest
69
{
710
final JsonFactory JSON_F = new JsonFactory();
@@ -142,7 +145,7 @@ private void _testWithLazyStringRead(int readMode) throws Exception
142145
assertEquals(8, p.getCurrentLocation().getColumnNr());
143146
p.close();
144147
}
145-
148+
146149
// for [core#533]
147150
public void testUtf8Bom() throws Exception
148151
{
@@ -231,4 +234,75 @@ private byte[] withUtf8Bom(byte[] bytes) {
231234
System.arraycopy(bytes, 0, arr, 3, bytes.length);
232235
return arr;
233236
}
237+
238+
// [core#603]
239+
public void testBigPayload() throws IOException {
240+
JsonLocation loc;
241+
JsonParser p;
242+
243+
String doc = "{\"key\":\"" + generateRandomAlpha(50000) + "\"}";
244+
245+
p = createParserUsingStream(JSON_F, doc, "UTF-8");
246+
247+
assertToken(JsonToken.START_OBJECT, p.nextToken());
248+
loc = p.getTokenLocation();
249+
assertEquals(0, loc.getByteOffset());
250+
assertEquals(-1L, loc.getCharOffset());
251+
assertEquals(1, loc.getLineNr());
252+
assertEquals(1, loc.getColumnNr());
253+
loc = p.getCurrentLocation();
254+
assertEquals(1, loc.getByteOffset());
255+
assertEquals(-1L, loc.getCharOffset());
256+
assertEquals(1, loc.getLineNr());
257+
assertEquals(2, loc.getColumnNr());
258+
259+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
260+
loc = p.getTokenLocation();
261+
assertEquals(1, loc.getByteOffset());
262+
assertEquals(-1L, loc.getCharOffset());
263+
assertEquals(1, loc.getLineNr());
264+
assertEquals(2, loc.getColumnNr());
265+
loc = p.getCurrentLocation();
266+
assertEquals(8, loc.getByteOffset());
267+
assertEquals(-1L, loc.getCharOffset());
268+
assertEquals(1, loc.getLineNr());
269+
assertEquals(9, loc.getColumnNr());
270+
271+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
272+
loc = p.getTokenLocation();
273+
assertEquals(7, loc.getByteOffset());
274+
assertEquals(-1L, loc.getCharOffset());
275+
assertEquals(1, loc.getLineNr());
276+
assertEquals(8, loc.getColumnNr());
277+
loc = p.getCurrentLocation();
278+
assertEquals(8, loc.getByteOffset());
279+
assertEquals(-1L, loc.getCharOffset());
280+
assertEquals(1, loc.getLineNr());
281+
assertEquals(9, loc.getColumnNr());
282+
283+
p.getTextCharacters();
284+
loc = p.getTokenLocation();
285+
assertEquals(7, loc.getByteOffset());
286+
assertEquals(-1L, loc.getCharOffset());
287+
assertEquals(1, loc.getLineNr());
288+
assertEquals(8, loc.getColumnNr());
289+
loc = p.getCurrentLocation();
290+
assertEquals(doc.length() - 1, loc.getByteOffset());
291+
assertEquals(-1L, loc.getCharOffset());
292+
assertEquals(1, loc.getLineNr());
293+
assertEquals(doc.length(), loc.getColumnNr());
294+
295+
p.close();
296+
}
297+
298+
private String generateRandomAlpha(int length) {
299+
StringBuilder sb = new StringBuilder(length);
300+
Random rnd = new Random(length);
301+
for (int i = 0; i < length; ++i) {
302+
// let's limit it not to include surrogate pairs:
303+
char ch = (char) ('A' + rnd.nextInt(26));
304+
sb.append(ch);
305+
}
306+
return sb.toString();
307+
}
234308
}

0 commit comments

Comments
 (0)