Issue a warning when we encounter a non-QName identityref
[yangtools.git] / yang / yang-data-codec-xml / src / main / java / org / opendaylight / yangtools / yang / data / codec / xml / XMLStreamWriterUtils.java
index cb9e2ec9129713e3915ca04e839831a6e1e2ba53..62766f4e4f148bd18a5dc6db81b772f7c05a5c95 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.yang.data.codec.xml;
 
 import com.google.common.annotations.VisibleForTesting;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import javax.xml.stream.XMLStreamException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -28,6 +30,10 @@ import org.slf4j.LoggerFactory;
  */
 abstract class XMLStreamWriterUtils {
     private static final Logger LOG = LoggerFactory.getLogger(XMLStreamWriterUtils.class);
+    /**
+     * Warn-once set of identityref nodes which were found to be normalized to a different object than a QName.
+     */
+    private static final Set<QName> IDENTITYREF_WARNED = ConcurrentHashMap.newKeySet();
 
     /**
      * Encode a value into a String in the context of a XML stream writer. This method assumes the start and end of
@@ -108,7 +114,10 @@ abstract class XMLStreamWriterUtils {
         }
 
         final QName qname = type.getQName();
-        LOG.debug("Value of {}:{} is not a QName but {}", qname.getNamespace(), qname.getLocalName(), value.getClass());
+        if (IDENTITYREF_WARNED.add(qname)) {
+            LOG.warn("Value of {}:{} is not a QName but {}. Please the source of this data", qname.getNamespace(),
+                qname.getLocalName(), value.getClass(), new Throwable());
+        }
         return value.toString();
     }