-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Expose byte offsets on XContentParser via getCurrentLocation() #143501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
quackaplop
merged 5 commits into
elastic:main
from
quackaplop:feature/xcontent-location-offsets
Mar 5, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f3c913
Expose byte offsets on XContentParser via getCurrentLocation()
quackaplop 634d64f
Add changelog for #143501
quackaplop 288da80
Add streaming JSON navigation + byte-slicing tests
quackaplop f481c7a
Rename XContentLocation.UNDEFINED to INVALID
quackaplop 38501c9
Address review feedback: remove INVALID, add validity methods
quackaplop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 143501 | ||
| summary: Expose byte offsets on XContentParser via getCurrentLocation() | ||
| area: Infra/Core | ||
| type: enhancement | ||
| issues: | ||
| - 142873 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
604 changes: 604 additions & 0 deletions
604
...test/java/org/elasticsearch/xcontent/provider/json/JsonXContentParserByteOffsetTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
libs/x-content/src/test/java/org/elasticsearch/xcontent/XContentLocationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.xcontent; | ||
|
|
||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| public class XContentLocationTests extends ESTestCase { | ||
|
|
||
| public void testTwoArgConstructorDefaultsByteOffset() { | ||
| XContentLocation loc = new XContentLocation(1, 5); | ||
| assertEquals(1, loc.lineNumber()); | ||
| assertEquals(5, loc.columnNumber()); | ||
| assertEquals(-1L, loc.byteOffset()); | ||
| } | ||
|
|
||
| public void testThreeArgConstructorPreservesAllFields() { | ||
| XContentLocation loc = new XContentLocation(3, 10, 42L); | ||
| assertEquals(3, loc.lineNumber()); | ||
| assertEquals(10, loc.columnNumber()); | ||
| assertEquals(42L, loc.byteOffset()); | ||
| } | ||
|
|
||
| public void testUnknownHasByteOffsetMinusOne() { | ||
| assertEquals(-1, XContentLocation.UNKNOWN.lineNumber()); | ||
| assertEquals(-1, XContentLocation.UNKNOWN.columnNumber()); | ||
| assertEquals(-1L, XContentLocation.UNKNOWN.byteOffset()); | ||
| } | ||
|
|
||
| public void testEqualityIncludesByteOffset() { | ||
| XContentLocation a = new XContentLocation(1, 1, 0L); | ||
| XContentLocation b = new XContentLocation(1, 1, 99L); | ||
| XContentLocation c = new XContentLocation(1, 1, 0L); | ||
| assertNotEquals(a, b); | ||
| assertEquals(a, c); | ||
| assertEquals(a.hashCode(), c.hashCode()); | ||
| } | ||
|
|
||
| public void testHasValidLineNumber() { | ||
| assertTrue(new XContentLocation(1, 5, 0L).hasValidLineNumber()); | ||
| assertTrue(new XContentLocation(100, 1).hasValidLineNumber()); | ||
| assertFalse(new XContentLocation(0, 1).hasValidLineNumber()); | ||
| assertFalse(new XContentLocation(-1, 1).hasValidLineNumber()); | ||
| assertFalse(XContentLocation.UNKNOWN.hasValidLineNumber()); | ||
| } | ||
|
|
||
| public void testHasValidColumnNumber() { | ||
| assertTrue(new XContentLocation(1, 1, 0L).hasValidColumnNumber()); | ||
| assertTrue(new XContentLocation(1, 99).hasValidColumnNumber()); | ||
| assertFalse(new XContentLocation(1, 0).hasValidColumnNumber()); | ||
| assertFalse(new XContentLocation(1, -1).hasValidColumnNumber()); | ||
| assertFalse(XContentLocation.UNKNOWN.hasValidColumnNumber()); | ||
| } | ||
|
|
||
| public void testHasValidByteOffset() { | ||
| assertTrue(new XContentLocation(1, 1, 0L).hasValidByteOffset()); | ||
| assertTrue(new XContentLocation(1, 1, 999L).hasValidByteOffset()); | ||
| assertFalse(new XContentLocation(1, 1).hasValidByteOffset()); | ||
| assertFalse(new XContentLocation(1, 1, -1L).hasValidByteOffset()); | ||
| assertFalse(XContentLocation.UNKNOWN.hasValidByteOffset()); | ||
| } | ||
|
|
||
| public void testToStringOmitsByteOffset() { | ||
| XContentLocation loc = new XContentLocation(5, 12, 100L); | ||
| assertEquals("5:12", loc.toString()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.