Bug 484: Fix XmlDocumentUtils.toDocument to handle anyxml 39/7339/2
authortpantelis <tpanteli@brocade.com>
Tue, 27 May 2014 17:02:23 +0000 (13:02 -0400)
committertpantelis <tpanteli@brocade.com>
Tue, 27 May 2014 17:02:23 +0000 (13:02 -0400)
For anyxml data, a ClassCastException occurs at
XmlDocumentUtils.createXmlRootElement(XmlDocumentUtils.java:180) when
blindly casting the schema instance to DataNodeContainer - the actual
instance is an AnyXmlSchemaNode. To prevent this, the code should first
check "schema instanceof DataNodeContainer". 'childSchema' will be null
but that's expected for anyxml as it doesn't have a schema.

Change-Id: Ib2497e99ddf329961114c214320f6283d13a5272
Signed-off-by: tpantelis <tpanteli@brocade.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java

index 7b180f96651a8e81aacfc848f3d8364ea67b2da5..f8bf77967ff49a6ce1884a9362eaf084ad20c760 100644 (file)
@@ -176,7 +176,7 @@ public class XmlDocumentUtils {
         } else { // CompositeNode
             for (Node<?> child : ((CompositeNode) data).getValue()) {
                 DataSchemaNode childSchema = null;
-                if (schema != null) {
+                if (schema instanceof DataNodeContainer) {
                     childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
                     if (logger.isDebugEnabled()) {
                         if (childSchema == null) {