From 5bc26d07dce3555aa57af39c45d3c1812794f05f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 4 Jun 2020 13:22:27 +0200 Subject: [PATCH] Issue a warning when we encounter a non-QName identityref 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 --- .../yang/data/codec/xml/XMLStreamWriterUtils.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamWriterUtils.java b/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamWriterUtils.java index cb9e2ec912..62766f4e4f 100644 --- a/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamWriterUtils.java +++ b/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamWriterUtils.java @@ -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 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(); } -- 2.36.6