Do not create effective copy for unsupported statements
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 04bb3d6cdb353629fbc3abddda3c61da4224d9bc..c7dadcae9f9bc4265dd60da6bbc7f45e6cd1f80e 100644 (file)
@@ -727,7 +727,12 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     @Override
     final ReactorStmtCtx<?, ?, ?> asEffectiveChildOf(final StatementContextBase<?, ?, ?> parent, final CopyType type,
             final QNameModule targetModule) {
-        final ReactorStmtCtx<A, D, E> copy = copyAsChildOfImpl(parent, type, targetModule);
+        if (!isSupportedToBuildEffective() || !isSupportedByFeatures()) {
+            // Do not create effective copies, as they cannot be built anyway
+            return null;
+        }
+
+        final var copy = copyAsChildOfImpl(parent, type, targetModule);
         if (copy == null) {
             // The statement fizzled, this should never happen, perhaps a verify()?
             return null;