Fix Subtree filter failing prefix lookup in element. 06/20806/4
authorTomas Cere <tcere@cisco.com>
Wed, 20 May 2015 11:45:36 +0000 (13:45 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 4 Jun 2015 10:43:20 +0000 (10:43 +0000)
If element is f.ex a mac adress subtree filter would
try to match a nonexisting prefix.

Change-Id: Id23d78f6c7312f7c7b0b4f92f1cd99d97932de7f
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java

index 566dfde7c3f3117f7c01af10655f4cf4c18bc453..d56648cdf059c4620b14625d9206cd34467d0484 100644 (file)
@@ -167,16 +167,23 @@ public class SubtreeFilter {
     }
 
     private static boolean prefixedContentMatches(final XmlElement filter, final XmlElement src) throws NetconfDocumentedException {
-        final Map.Entry<String, String> prefixToNamespaceOfFilter = filter.findNamespaceOfTextContent();
-        final Map.Entry<String, String> prefixToNamespaceOfSrc = src.findNamespaceOfTextContent();
+        final Map.Entry<String, String> prefixToNamespaceOfFilter;
+        final Map.Entry<String, String> prefixToNamespaceOfSrc;
+        try {
+            prefixToNamespaceOfFilter = filter.findNamespaceOfTextContent();
+            prefixToNamespaceOfSrc = src.findNamespaceOfTextContent();
+        } catch (IllegalArgumentException e) {
+            //if we can't find namespace of prefix - it's not a prefix, so it doesn't match
+            return false;
+        }
 
         final String prefix = prefixToNamespaceOfFilter.getKey();
         // If this is not a prefixed content, we do not need to continue since content do not match
-        if(prefix.equals(XmlElement.DEFAULT_NAMESPACE_PREFIX)) {
+        if (prefix.equals(XmlElement.DEFAULT_NAMESPACE_PREFIX)) {
             return false;
         }
         // Namespace mismatch
-        if(!prefixToNamespaceOfFilter.getValue().equals(prefixToNamespaceOfSrc.getValue())) {
+        if (!prefixToNamespaceOfFilter.getValue().equals(prefixToNamespaceOfSrc.getValue())) {
             return false;
         }