From 924f84a35308c4d0d40d6339c8a17f81fa3aebf2 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 3 Apr 2022 22:21:49 +0200 Subject: [PATCH] Check null returns from NamespaceContext If we have a prefix that is not bould in the NamespaceContext, its getNamespaceURI() will return null. checkArgument() such return to provide better diagnostic than the implied NPE from XMLNamespace. Change-Id: Ia49a9dbdf5dd4a3b8608f1e63dd0390130312897 Signed-off-by: Robert Varga --- .../yang/data/codec/xml/IdentityrefXmlCodec.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java b/codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java index e1b9506da2..9f9980e8f1 100644 --- a/codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java +++ b/codec/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.data.codec.xml; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; +import com.google.common.base.MoreObjects; import java.util.Iterator; import java.util.Map.Entry; import javax.xml.namespace.NamespaceContext; @@ -28,7 +29,7 @@ final class IdentityrefXmlCodec implements XmlCodec { private final QNameModule parentModule; IdentityrefXmlCodec(final EffectiveModelContext context, final QNameModule parentModule) { - this.schemaContext = requireNonNull(context); + schemaContext = requireNonNull(context); this.parentModule = requireNonNull(parentModule); } @@ -45,6 +46,8 @@ final class IdentityrefXmlCodec implements XmlCodec { } final String prefixedNS = ctx.getNamespaceURI(prefix); + checkArgument(prefixedNS != null, "Failed to resolve prefix %s", prefix); + final Iterator modules = schemaContext.findModules(XMLNamespace.of(prefixedNS)).iterator(); checkArgument(modules.hasNext(), "Could not find module for namespace %s", prefixedNS); @@ -62,4 +65,9 @@ final class IdentityrefXmlCodec implements XmlCodec { } ctx.writeCharacters(str); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("module", parentModule).toString(); + } } -- 2.36.6