- final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(YangInstanceIdentifier.EMPTY);
- if (node.isPresent()) {
- final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(
- YangInstanceIdentifier.EMPTY, node.get());
+ final var data = preExistingData.orElseThrow();
+ if (treeId.isEmpty()) {
+ if (data instanceof DataContainerNode container) {
+ if (container.isEmpty()) {
+ // If we are listening on root of data tree we still get empty normalized node, root is always
+ // present, we should filter this out separately and notify it by 'onInitialData()' once.
+ // Otherwise, it is just a valid data node with empty value which also should be notified by
+ // "onDataTreeChanged(List<DataTreeCandidate>)".
+ listener.onInitialData();
+ return reg;
+ }
+ } else {
+ throw new IllegalStateException("Unexpected root node type " + data.contract());
+ }
+ }