Merge "Fix findbugs violations in netconf"
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / schema / mapping / NetconfMessageTransformer.java
index fc31a256aae0a4738bafe139e6f43ab456b94db7..e146131d9b0fbd87e4426234e26c6eb942c40149 100644 (file)
@@ -16,12 +16,13 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.Date;
 import java.util.Map;
 import javax.annotation.Nonnull;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
@@ -36,6 +37,7 @@ import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -54,6 +56,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
 
 public class NetconfMessageTransformer implements MessageTransformer<NetconfMessage> {
 
@@ -82,7 +85,6 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         this.strictParsing = strictParsing;
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public synchronized DOMNotification toNotification(final NetconfMessage message) {
         final Map.Entry<Date, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
@@ -113,7 +115,8 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                     notificationAsContainerSchemaNode, strictParsing);
             xmlParser.traverse(new DOMSource(element));
             content = (ContainerNode) resultHolder.getResult();
-        } catch (final Exception e) {
+        } catch (XMLStreamException | URISyntaxException | IOException | ParserConfigurationException
+                | SAXException | UnsupportedOperationException e) {
             throw new IllegalArgumentException(String.format("Failed to parse notification %s", element), e);
         }
         return new NetconfDeviceNotification(content, stripped.getKey());
@@ -121,10 +124,8 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
 
     private static NotificationDefinition getMostRecentNotification(
             final Collection<NotificationDefinition> notificationDefinitions) {
-        Comparator<NotificationDefinition> cmp = (o1, o2) ->
-                o1.getQName().getRevision().compareTo(o2.getQName().getRevision());
-
-        return Collections.max(notificationDefinitions, cmp);
+        return Collections.max(notificationDefinitions, (o1, o2) ->
+            Revision.compare(o1.getQName().getRevision(), o2.getQName().getRevision()));
     }
 
     @Override
@@ -177,7 +178,6 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                 || rpc.getNamespace().equals(NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME.getNamespace());
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public synchronized DOMRpcResult toRpcResult(final NetconfMessage message, final SchemaPath rpc) {
         final NormalizedNode<?, ?> normalizedNode;
@@ -195,7 +195,8 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                         strictParsing);
                 xmlParser.traverse(new DOMSource(xmlData));
                 dataNode = (ContainerNode) resultHolder.getResult();
-            } catch (final Exception e) {
+            } catch (XMLStreamException | URISyntaxException | IOException | ParserConfigurationException
+                    | SAXException e) {
                 throw new IllegalArgumentException(String.format("Failed to parse data response %s", xmlData), e);
             }
 
@@ -234,7 +235,8 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                             rpcDefinition.getOutput(), strictParsing);
                     xmlParser.traverse(new DOMSource(element));
                     normalizedNode = resultHolder.getResult();
-                } catch (final Exception e) {
+                } catch (XMLStreamException | URISyntaxException | IOException | ParserConfigurationException
+                        | SAXException e) {
                     throw new IllegalArgumentException(String.format("Failed to parse RPC response %s", element), e);
                 }
             }