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; 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