Skip to content
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

Introduce BsonUtil.mutableDeepCopy #1081

Merged
merged 4 commits into from Feb 13, 2023

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Feb 7, 2023

Currently we have at least two places (that I know of) where we rely on BsonDocument.clone returning not only a deep copy, but mutable deep copy:

  1. AbstractConstructibleBson.newMerged
  2. The new method ClientEncryption.createEncryptedCollection introduced in Add the ClientEncryption.createEncryptedCollection helper method #1079.

@rozza pointed out that RawBsonDocument breaks the "mutable" part and can come from users: the cloneIsDeepCopyAndMutable test added in this PR demonstrates this.

RawBsonDocument.clone returns BsonDocument (not RawBsonDocument), and documents nothing about its behavior (neither does BsonDocument.clone). So while there may be different approaches of solving the problem, these facts allow for the straightforward approach to fix the problem proposed in this PR.

JAVA-4874

Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - please also add a Jira ticket to associate with this change.

@@ -23,13 +23,16 @@
import org.bson.json.JsonReader;
import org.bson.json.JsonWriter;
import org.bson.json.JsonWriterSettings;
import org.junit.Test;
import org.junit.jupiter.api.Test;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@jyemin
Copy link
Contributor

jyemin commented Feb 8, 2023

I'm not so sure about this, and would like to discuss it in the context of a Jira ticket.

@stIncMale
Copy link
Member Author

@jyemin, @rozza I created a corresponding Jira ticket: JAVA-4874.

@stIncMale
Copy link
Member Author

Instead of modifying RawBsonDocument.clone, I introduced Util.mutableDeepCopy.

@stIncMale stIncMale changed the title Make sure that BsonDocument.clone returns a mutable deep copy Introduce Util.mutableDeepCopy Feb 10, 2023
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like the lack of description in name of the Util class - suggest BsonDocumentHelper or BsonDocumentUtil. Will make it more discoverable in the future.

I like the tests use a mix of BsonValue (BsonDocumentWrapper, RawBsonDocument etc) types.

Other than the name - LGTM

@stIncMale
Copy link
Member Author

@rozza Renamed to BsonUtil.

@stIncMale stIncMale changed the title Introduce Util.mutableDeepCopy Introduce BsonUtil.mutableDeepCopy Feb 10, 2023
Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stIncMale stIncMale merged commit a748926 into mongodb:master Feb 13, 2023
@stIncMale stIncMale deleted the rawBsonDocumentClone branch February 13, 2023 19:44
@stIncMale stIncMale self-assigned this Feb 19, 2023
ispringer pushed a commit to evergage/mongo-java-driver that referenced this pull request May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants