AssertionError thrown by Var.class : setParentNode(QueryModelNode parent) during the execution of Visitor/Inference-related Unit Tests #4901
-
Dear RDF4J community, I would like to preface this by thanking all of you in advance for your contributions and potential assistance. I am working on my own fork of Apache Rya. I have been refactoring to update various dependencies. The original version of RDF4J used in the aforementioned mirror is 2.3.1. The transition from RDF4J major version 2 to 3 was pretty straightforward, but I am having a bit of trouble with transition from RDF4J major version 3 to 4. The version of RDF4J that I am using now is 4.3.9 and when running some tests (AllValuesFromVisitorTest, DomainRangeVisitorTest, HasSelfValueVisitorTest, HasValueVisitorTest, IntersectionOfVisitorTest, ReflexivePropertyVisitorTest, etc.) I consistently get the same AssertionError. For reference, the original source code for these tests is located here. I will share the output of AllValuesFromVisitorTest here.
It seems that when a new StatementPattern is constructed, Var.class is expecting this.getParentNode() to return null
When I turn on debugging with IntelliJ, this.getParentNode() is evaluated to be StatementPattern. Consequently, the assertion that this.getParentNode() == null fails (obviously). When the unit test was originally written, there was no such method in Var.class. I welcome any ideas to help correct this issue, as it is clear I must be misunderstanding the core concept. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We've had issues in the code with the parent pointer of the query tree nodes not pointing to the correct parent because nodes have been shared between multiple other nodes. To help mitigate this we have made the Var node parent pointer essentially immutable once it's been set to force us to always mint a new Var object instead of reusing an existing one. This doesn't apply to other nodes, since it's useful to be able to manipulate the query tree without having to rebuild every subtree for each operation. I would look through your stack trace and check which of your methods are reusing an existing Var node when creating the StatementPattern. A quick fix is typically to clone the Var node. This will give you a copy of your Var node without a parent node set. |
Beta Was this translation helpful? Give feedback.
We've had issues in the code with the parent pointer of the query tree nodes not pointing to the correct parent because nodes have been shared between multiple other nodes. To help mitigate this we have made the Var node parent pointer essentially immutable once it's been set to force us to always mint a new Var object instead of reusing an existing one. This doesn't apply to other nodes, since it's useful to be able to manipulate the query tree without having to rebuild every subtree for each operation.
I would look through your stack trace and check which of your methods are reusing an existing Var node when creating the StatementPattern.
A quick fix is typically to clone the Var node. …