Issue a warning when we encounter a non-QName identityref 51/90251/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 4 Jun 2020 11:22:27 +0000 (13:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 4 Jun 2020 12:21:37 +0000 (14:21 +0200)
identityref types are required to be normalized as a QName, but we
have a legacy fallback to using .toString(). Issue an explicit
warning when this happens.

JIRA: YANGTOOLS-1110
Change-Id: Ia9cfc824e03d7641c7081f479f7a4d6c7c98062c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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();
     }