EgorBaranovEnjoysTyping commented on code in PR #13262: URL: https://github.com/apache/ignite/pull/13262#discussion_r3482019192
########## modules/commons/src/main/java/org/apache/ignite/internal/util/tostring/NodeRecursionMonitor.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.tostring; + +import java.util.IdentityHashMap; +import java.util.Optional; +import org.apache.ignite.internal.util.GridStringBuilder; + +/** + * Abstract base class for nodes that tracks object references + * to prevent infinite recursion during string representation building. + */ +abstract class NodeRecursionMonitor extends GridToStringNode { + /** Thread-local registry to track objects currently being processed. */ + static final ThreadLocal<IdentityHashMap<Object, NodeRecursionMonitor>> OBJECT_REGISTRY = + ThreadLocal.withInitial(IdentityHashMap::new); + + /** The object being monitored for recursive references. */ + private final Object obj; + + /** Flag indicating if the identity hash code should be appended to the output. */ + boolean hashIsRequired; + + /** + * Constructor. + * @param propName Name of the property. + * @param obj Object to monitor for recursion. + */ + NodeRecursionMonitor(String propName, Object obj) { + super(propName); + this.obj = obj; + } + + /** + * Registers the current node in the thread-local registry for the given object. + * @param node The node to register. + */ + void aqcuireRecursionMonitor(NodeRecursionMonitor node) { Review Comment: Done -- 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]
