補間された文字列を使用して子ノードを作成すると、ドット表記を使用してそのノードに再度アクセスできなくなります。問題のノードにアクセスしようとすると、null
. ループしてノードを探すと、ノードを取得できますが、children()
そうする必要はありません。次のコードは問題を再現します。
// All works as expected when an interpolated string isn't used to create the child node
def rootNode = new Node(null, "root")
def childNode = new Node(rootNode, "child", [attr: "test"])
def childNodeCopy = rootNode.child[0]
println childNode.toString() // child[attributes={attr=test}; value=[]]
println childNodeCopy.toString() // child[attributes={attr=test}; value=[]]
println childNode.toString() == childNodeCopy.toString() // true
// But when an interpolated string is used the child node cannot be accessed from the root
rootNode = new Node(null, "root")
def childName = "child"
childNode = new Node(rootNode, "$childName", [attr: "test"])
childNodeCopy = rootNode.child[0]
println childNode.toString() // child[attributes={attr=test}; value=[]]
println childNodeCopy.toString() // null
println childNode.toString() == childNodeCopy.toString() // false