From 494147c876379e80c5568f3f827e8cd7b1906614 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 2 Mar 2023 23:40:32 +0100 Subject: [PATCH 1/2] Added failing test --- .../javarosa/core/model/test/FormDefTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/org/javarosa/core/model/test/FormDefTest.java b/src/test/java/org/javarosa/core/model/test/FormDefTest.java index 36ba11c26..69930e0e4 100644 --- a/src/test/java/org/javarosa/core/model/test/FormDefTest.java +++ b/src/test/java/org/javarosa/core/model/test/FormDefTest.java @@ -266,6 +266,34 @@ public void nestedRepeatRelevance_updatesBasedOnParentPosition() throws IOExcept scenario.next(); assertThat(scenario.refAtIndex(), is(getRef("/data/outer[0]/inner[0]"))); } + + @Test + public void innerRepeatGroupIsIrrelevant_whenItsParentRepeatGroupDoesNotExist() throws IOException, XFormParser.ParseException { + Scenario scenario = Scenario.init("Nested repeat relevance", html( + head( + title("Nested repeat relevance"), + model( + mainInstance(t("data id=\"nested-repeat-relevance\"", + t("outer", + t("inner", + t("q1") + ) + ) + )) + )), + body( + repeat("/data/outer", + repeat("/data/outer/inner", + input("/data/outer/inner/q1") + ) + ) + ))); + + + FormDef formDef = scenario.getFormDef(); + // outer[1] does not exist at this moment, we only have outer[0]. Checking if its inner repeat group is relevant should be possible and return false. + assertThat(formDef.isRepeatRelevant(getRef("/data/outer[1]/inner[0]")), is(false)); + } //endregion @Test From 8093353824cfab5676ec7cc7afb84e368239ffa3 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 2 Mar 2023 23:41:47 +0100 Subject: [PATCH 2/2] Handle not existing parent nodes in isRepeatRelevant method --- src/main/java/org/javarosa/core/model/FormDef.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index b060b1904..e9832ab0f 100644 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -552,7 +552,7 @@ public boolean isRepeatRelevant(TreeReference repeatRef) { TreeReference parentPath = templNode.getParent().getRef().genericize(); TreeElement parentNode = mainInstance .resolveReference(parentPath.contextualize(repeatRef)); - relev = parentNode.isRelevant() && templNode.isRelevant(); + relev = parentNode != null && parentNode.isRelevant() && templNode.isRelevant(); } return relev;