-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Introduce BsonUtil.mutableDeepCopy
#1081
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
I'm not so sure about this, and would like to discuss it in the context of a Jira ticket. |
d1a0c31
to
a525a64
Compare
Instead of modifying |
BsonDocument.clone
returns a mutable deep copyUtil.mutableDeepCopy
There was a problem hiding this 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
JAVA-4874
@rozza Renamed to |
Util.mutableDeepCopy
BsonUtil.mutableDeepCopy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:AbstractConstructibleBson.newMerged
ClientEncryption.createEncryptedCollection
introduced in Add theClientEncryption.createEncryptedCollection
helper method #1079.@rozza pointed out that
RawBsonDocument
breaks the "mutable" part and can come from users: thecloneIsDeepCopyAndMutable
test added in this PR demonstrates this.RawBsonDocument.clone
returnsBsonDocument
(notRawBsonDocument
), and documents nothing about its behavior (neither doesBsonDocument.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