Dennis-Mircea commented on code in PR #1128:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/1128#discussion_r3343245083
##########
flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/utils/SpecUtils.java:
##########
@@ -130,16 +130,11 @@ private static <T> T checkNotNull(T object) {
}
}
+ @SuppressWarnings("unchecked")
public static <T> T clone(T object) {
if (object == null) {
return null;
}
- try {
- return (T)
- objectMapper.readValue(
- objectMapper.writeValueAsString(object),
object.getClass());
- } catch (JsonProcessingException e) {
- throw new IllegalStateException(e);
- }
+ return (T) objectMapper.convertValue(object, object.getClass());
Review Comment:
It clones and it does not return the object as-is.
The `convertValue(object, object.getClass())` runs a full `serialize ->
deserialize` round trip through a `TokenBuffer` (`object -> tokens -> new
object`), so the result is a genuine deep copy. I've added a `SpecUtilsTest`
case asserting the clone is a separate instance with equal content and that
mutating it doesn't affect the original, so the deep-copy guarantee is
protected against future Jackson upgrades.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]