From c75fc716f8c60dfdf267d078df66346c95dae7a4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 13 Aug 2021 22:14:41 +0200 Subject: [PATCH] Fix XmlPatchBodyReader revision handling There is a nullness bug around the conversions through string and calling Revision.of(). Our current interfaces allow us to do better, with fewer objects. Change-Id: I68163b7b8766e6063a27d280bae9c049a675ac76 Signed-off-by: Robert Varga --- .../jersey/providers/patch/XmlPatchBodyReader.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java index 927ca67d06..f3570b5ee6 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java @@ -26,6 +26,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLStreamException; import javax.xml.transform.dom.DOMSource; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -117,12 +118,11 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { targetNode = pathContext.getSchemaContext(); } else { // get namespace according to schema node from path context or value - final String namespace = firstValueElement == null - ? schemaNode.getQName().getNamespace().toString() : firstValueElement.getNamespaceURI(); + final XMLNamespace namespace = firstValueElement == null ? schemaNode.getQName().getNamespace() + : XMLNamespace.of(firstValueElement.getNamespaceURI()); // find module according to namespace - final Module module = pathContext.getSchemaContext().findModules(XMLNamespace.of(namespace)).iterator() - .next(); + final Module module = pathContext.getSchemaContext().findModules(namespace).iterator().next(); // initialize codec + set default prefix derived from module name final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec( @@ -130,8 +130,7 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { targetII = codec.deserialize(codec.serialize(pathContext.getInstanceIdentifier()) .concat(prepareNonCondXpath(schemaNode, target.replaceFirst("/", ""), firstValueElement, - namespace, - module.getQNameModule().getRevision().map(Revision::toString).orElse(null)))); + namespace, module.getQNameModule().getRevision().orElse(null)))); // move schema node schemaNode = verifyNotNull(codec.getDataContextTree().findChild(targetII).orElseThrow() @@ -224,7 +223,7 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { * @return Non-conditional XPath */ private static String prepareNonCondXpath(final @NonNull DataSchemaNode schemaNode, final @NonNull String target, - final @NonNull Element value, final @NonNull String namespace, final @NonNull String revision) { + final @NonNull Element value, final @NonNull XMLNamespace namespace, final @Nullable Revision revision) { final Iterator args = SLASH_SPLITTER.split(target.substring(target.indexOf(':') + 1)).iterator(); final StringBuilder nonCondXpath = new StringBuilder(); -- 2.36.6