Repository navigation
Conversation
BsonDocumentReader reset every mark to the position of the earliest outstanding mark, and stopped buffering after a reset, so another mark or the same mark could no longer be reset to. A mark now records the position of the iterator of its context and of the enclosing contexts, and a marked iterator keeps the values it returns, as BsonBinaryReader keeps its whole input.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
JAVA-6242
BsonDocumentReaderdidn't honour theBsonReaderMark.reset()contract when a mark wasn't the only one taken, or was reset more than once:BsonDocumentMarkableIterator.reset()always went back to the start of its buffer, which is the position of the earliest mark taken in that context. So resetting a later mark went back to the earlier one, as described in the ticket.BsonBinaryReaderandJsonReaderhandle both cases correctly, since their marks are positions in an input they keep.Fix
Marknow records the iterator position of its context and of each enclosing context, andreset()restores those positions. Before, every iterator in the chain went back to the start of its buffer.next()that dropped values from the buffer after a reset is gone. The buffer only holds references to values of the document the reader already holds, and it's released with the context when the reader leaves that document or array.Context.mark()andContext.reset()are protected, so I kept them unchanged.Marknow uses new private methods.Tests
BsonReaderMarkTest(JUnit 5) runs each case against bothBsonDocumentReaderandBsonBinaryReader, so the two readers are held to the same behaviour:On
main, all three fail forBsonDocumentReaderand pass forBsonBinaryReader. With the fix, all six pass. I also checked that each part of the change is needed: reverting any one of them makes at least one test fail.Ran locally with JDK 17:
./gradlew :bson:check(3,905 tests, with thespecificationssubmodule) and the tests ofbson-record-codec,bson-kotlinandbson-kotlinx.