anton-vinogradov commented on code in PR #13262: URL: https://github.com/apache/ignite/pull/13262#discussion_r3483046206
########## modules/commons/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringNodeFactory.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; + +import static org.apache.ignite.internal.util.tostring.GridToStringNode.identities; + +/** + * A factory class responsible for creating appropriate GridToStringNode instances + * based on the type and value of the object being processed. + */ +public class GridToStringNodeFactory { + /** + * Creates a list of nodes from arrays of property names and values. + * Handles sensitive data exclusion and node reuse from a thread-local cache. + * @param addNames Array of property names. + * @param addVals Array of property values. + * @param addSens Array of flags indicating if a property is sensitive. + * @param addLen The number of elements to process. + * @return A list of constructed GridToStringNode objects. + */ + public static List<GridToStringNode> getNodes(Object[] addNames, + Object[] addVals, + boolean[] addSens, + int addLen) { + List<GridToStringNode> result = new LinkedList<>(); Review Comment: "Unknown capacity" argues *for* `ArrayList`, not against it: `ArrayList` handles unknown size fine via amortized doubling and is cheaper per element (a single backing array vs. a node object + two links each), and this list is built once and then only iterated. `LinkedList` only pays off for frequent head/middle insert-remove, which doesn't happen here. ########## modules/commons/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringArrayNode.java: ########## @@ -0,0 +1,82 @@ +/* + * 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 org.apache.ignite.internal.util.GridStringBuilder; + +import static org.apache.ignite.internal.util.tostring.GridToStringBuilder.COLLECTION_LIMIT; +import static org.apache.ignite.internal.util.tostring.GridToStringNodeFactory.getGridToStringNode; + +/** + * A node that represents an array in the string representation. + * It creates nodes for each element of the array and formats the output with square brackets. + */ +class GridToStringArrayNode extends NodeRecursionMonitor { + /** An array of child nodes, each representing an element of the source array. */ + private final GridToStringNode[] nodes; + + /** The rule for appending a hint about skipped elements if the array is too large. */ + private final LongSequenceSkipRule skipRule; + + /** The class object representing the type of the array. */ + private final Class<?> arrType; + + /** + * Constructs a new array node. + * Iterates over the input array, creates a node for each element, + * and populates the internal array up to the collection size limit. + * @param propName The property name. + * @param arr The source array. + * @param arrType The class object of the array's type. + */ + GridToStringArrayNode(String propName, Object[] arr, Class<?> arrType) { + super(propName, arr); + try { + aqcuireRecursionMonitor(this); + this.arrType = arrType; + skipRule = new LongSequenceSkipRule(() -> arr.length); + nodes = new GridToStringNode[Math.min(COLLECTION_LIMIT, arr.length)]; + for (int i = 0; i < nodes.length; i++) { + final int idx = i; + nodes[idx] = getGridToStringNode(null, () -> arr[idx], () -> arr[idx].getClass()); Review Comment: You're right — `getGridToStringNode` calls `valSupplier.get()` and returns a `GridToStringNullNode` before the class supplier is ever invoked, and this is a lambda (`() -> child.getClass()`), not a bound method reference, so it can't NPE on a null element. Withdrawing this one. 👍 -- 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]
