Revert "Fix mandatory enforcer failure on augmented nodes"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ChoiceModificationStrategy.java
index b0d9826525c6cfeda7d78f8b3b3920702b3e8849..b79371f48dbc71150cbfe1f21099c92a3805d038 100644 (file)
@@ -54,12 +54,20 @@ final class ChoiceModificationStrategy extends Visible<ChoiceSchemaNode> {
 
         final Builder<PathArgument, ModificationApplyOperation> childBuilder = ImmutableMap.builder();
         final Builder<PathArgument, CaseEnforcer> enforcerBuilder = ImmutableMap.builder();
-        for (final CaseSchemaNode caze : schema.getCases().values()) {
+        for (final CaseSchemaNode caze : schema.getCases()) {
             final CaseEnforcer enforcer = CaseEnforcer.forTree(caze, treeConfig);
             if (enforcer != null) {
-                for (final Entry<NodeIdentifier, DataSchemaNode> e : enforcer.getChildEntries()) {
-                    childBuilder.put(e.getKey(), SchemaAwareApplyOperation.from(e.getValue(), treeConfig));
-                    enforcerBuilder.put(e.getKey(), enforcer);
+                for (final Entry<NodeIdentifier, DataSchemaNode> entry : enforcer.getChildEntries()) {
+                    final ModificationApplyOperation childOper;
+                    try {
+                        childOper = SchemaAwareApplyOperation.from(entry.getValue(), treeConfig);
+                    } catch (ExcludedDataSchemaNodeException e) {
+                        // This should never happen as enforcer performs filtering
+                        throw new IllegalStateException("Enforcer references out-of-tree child " + entry, e);
+                    }
+
+                    childBuilder.put(entry.getKey(), childOper);
+                    enforcerBuilder.put(entry.getKey(), enforcer);
                 }
                 for (final Entry<AugmentationIdentifier, AugmentationSchemaNode> e
                         : enforcer.getAugmentationEntries()) {