Fix ReactorStmtCtx.calculateParentRefcount() 91/104191/2
authorSangwook Ha <sangwook.ha@verizon.com>
Wed, 4 Jan 2023 04:12:51 +0000 (20:12 -0800)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jan 2023 12:03:14 +0000 (13:03 +0100)
commit4005067996f7415546722ab9df0870adcd123694
tree0c54d8b3c650c1b65be3d88e829860dd371d8bd4
parent26151dbea9819243549196a54f4ac2f6822c444d
Fix ReactorStmtCtx.calculateParentRefcount()

If we have an empty grouping, which is referenced via augment-uses to a
different module, then if that module is buildEffective()'d first, we
end up with the grouping being swept.

This turns out to be a bug in parentRef determination -- in this
particular case we observe parent being REFCOUNT_NONE and invoke it
recursively -- and since the parent is a module, it itself does not have
a parentRef. This leads to us thinking the grouping does not have a
parentRef, whereas it does.

Update calculateParentRefcount() to recognize parent.refCount == 0 as
parent holding us down.

The problem manifests itself in the test when the models are processed
in order foo.yang, bar.yang -- but not when bar.yang is processed before
foo.yang.

Unfortunately the order of processing is not predictable in
BuildGlobalContext, hence we repeat the test 4 times.

JIRA: YANGTOOLS-1474
Change-Id: Ib3d55fb92d5a6d34230722ab1cd39e8f8831b6fe
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit ad55ca2b2e72f15d7963cfcb011e4f7610889fce)
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1474Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1474/bar.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1474/foo.yang [new file with mode: 0644]