final NodeCodecContext<?> childContext = byMethod.get(method).get();
@SuppressWarnings("unchecked")
final Optional<NormalizedNode<?, ?>> domChild = domData.getChild(childContext.getDomPathArgument());
- if (domChild.isPresent()) {
- return childContext.deserializeObject(domChild.get());
- } else if (childContext instanceof LeafNodeCodecContext) {
- return ((LeafNodeCodecContext)childContext).defaultObject();
- } else {
- return null;
- }
+
+ // We do not want to use Optional.map() here because we do not want to invoke defaultObject() when we have
+ // normal value because defaultObject() may end up throwing an exception intentionally.
+ return domChild.isPresent() ? childContext.deserializeObject(domChild.get()) : childContext.defaultObject();
}
@SuppressWarnings("checkstyle:illegalCatch")
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCachingCodec;
import org.opendaylight.yangtools.concepts.Codec;
return ChildAddressabilitySummary.UNADDRESSABLE;
}
- /**
- * Return the default value object.
- *
- * @return The default value object, or null if the default value is not defined.
- */
- @Nullable Object defaultObject() {
+ @Override
+ Object defaultObject() {
return defaultObject;
}
}
import com.google.common.collect.ImmutableMap;
import java.util.List;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
import org.opendaylight.yangtools.concepts.Codec;
}
}
+ /**
+ * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
+ * exceptions, which are propagated as-is upwards the stack.
+ *
+ * @return The default value object, or null if the default value is not defined.
+ */
+ @Nullable Object defaultObject() {
+ return null;
+ }
+
protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);
}