From fa9496bd3bf61d132c27823caea5bbcd9fd19b6c Mon Sep 17 00:00:00 2001 From: Frens Jan Rumph Date: Tue, 20 Feb 2024 09:17:33 +0100 Subject: [PATCH] GH-4915 Fixed setting parent in ValueExprTripleRef#replaceChildNode --- .../query/algebra/ValueExprTripleRef.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/ValueExprTripleRef.java b/core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/ValueExprTripleRef.java index 147e8a57f97..256d606ab1a 100644 --- a/core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/ValueExprTripleRef.java +++ b/core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/ValueExprTripleRef.java @@ -20,13 +20,9 @@ public class ValueExprTripleRef extends AbstractQueryModelNode implements ValueE public ValueExprTripleRef(String extName, Var s, Var p, Var o) { this.exprVarName = extName; - subjectVar = s; - predicateVar = p; - objectVar = o; - - subjectVar.setParentNode(this); - predicateVar.setParentNode(this); - objectVar.setParentNode(this); + setSubjectVar(s); + setPredicateVar(p); + setObjectVar(o); } public String getExtVarName() { @@ -45,6 +41,21 @@ public Var getObjectVar() { return objectVar; } + private void setSubjectVar(Var s) { + subjectVar = s; + subjectVar.setParentNode(this); + } + + private void setPredicateVar(Var p) { + predicateVar = p; + predicateVar.setParentNode(this); + } + + private void setObjectVar(Var o) { + objectVar = o; + objectVar.setParentNode(this); + } + @Override public void visitChildren(QueryModelVisitor visitor) throws X { if (subjectVar != null) { @@ -84,17 +95,16 @@ public ValueExprTripleRef clone() { @Override public void visit(QueryModelVisitor visitor) throws X { visitor.meetOther(this); - // visitChildren(visitor); } @Override public void replaceChildNode(QueryModelNode current, QueryModelNode replacement) { if (subjectVar == current) { - subjectVar = (Var) replacement; + setSubjectVar((Var) replacement); } else if (predicateVar == current) { - predicateVar = (Var) replacement; + setPredicateVar((Var) replacement); } else if (objectVar == current) { - objectVar = (Var) replacement; + setObjectVar((Var) replacement); } else { super.replaceChildNode(current, replacement); }