-
Notifications
You must be signed in to change notification settings - Fork 110
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
IonSystem.clone not doing deep copy as the doc indicates #950
Comments
The test as written should be expected to fail due to the following guidance in the
Ideally it would fail in the location indicated below:
Unfortunately it does not, and it's highly likely that fixing this would break existing users who are getting away with doing this. As a result, we may be stuck with the current behavior in this major version of IonJava, namely that doing this may fail in some subsequent location, or may not. The following works:
|
I understand that it should have failed when adding an IonValue to another container created by other IonSystem, however it doesn't and changing this behavior is current major version is not safe and dangerous. But I'd expect when I do ionSystem1.clone(ionValue), the resulting IonValue is fully in ionSystem1. The documentation of clone does indicate that, this is a pattern to use when intended to create IonValue for another system.
And similarly here
While changing the above behavior is dangerous, changing the clone behavior should be safe so that it does what it says it does, a deep copy and once I get a deep copy with new IonSystem I can expect it to have just one IonSystem I cloned with. |
Also, with current behavior even this is not fullproof. Now, imagine requestStruct and responseStruct itself a deeply nested, then it is still possible that some part of those requestStruct is with different IonSystem and then in assert if I try to assert those, those will still be different. Only solution I think will work is to make ionSystem.clone return a deep clone.
|
The Javadoc on IonSystem indicates to use IonSystem.clone to create a copy of value for use by a different system.
ion-java/src/main/java/com/amazon/ion/IonSystem.java
Lines 33 to 43 in 9e6c570
Similarly, the Javadoc on ValueFactory which IonSystems extends mentions that clone does the deep copy and it allows you to shift data from one factory instance to another.
ion-java/src/main/java/com/amazon/ion/ValueFactory.java
Lines 570 to 589 in 9e6c570
So, I'd expect that when I do
ionSystem.clone(ionValue)
then result is a deep copy with everything with ionSystem, but I found this test fails indicating it didn't do that.The text was updated successfully, but these errors were encountered: