Use URI.create() 91/57591/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 21 May 2017 14:13:33 +0000 (16:13 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 22 May 2017 14:20:47 +0000 (16:20 +0200)
We wrap 'new URI(String)' in a try-catch block, which is not really
necessary -- use URI.create(String) to get pretty much the same
behavior (except for the exception thrown).

Change-Id: Id9baa17dddb564b2be6d2258a1d73947a67c15f6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java

index 30cd1dae8ba111c2279f6c1b4511dc94a0025cf2..3321b269fbfed5e387e1f87598f5393ce553b80d 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.CheckedFuture;
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
@@ -61,14 +60,14 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
 
     private static final Logger LOG = LoggerFactory.getLogger(RuntimeRpc.class);
 
-    private final CurrentSchemaContext schemaContext;
     private static final XMLOutputFactory XML_OUTPUT_FACTORY;
 
     static {
         XML_OUTPUT_FACTORY = XMLOutputFactory.newFactory();
-        XML_OUTPUT_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
+        XML_OUTPUT_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
     }
 
+    private final CurrentSchemaContext schemaContext;
     private final DOMRpcService rpcService;
 
     public RuntimeRpc(final String netconfSessionIdForReporting, final CurrentSchemaContext schemaContext,
@@ -99,14 +98,8 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
     }
 
     private static URI createNsUri(final String namespace) {
-        final URI namespaceURI;
-        try {
-            namespaceURI = new URI(namespace);
-        } catch (final URISyntaxException e) {
-            // Cannot occur, namespace in parsed XML cannot be invalid URI
-            throw new IllegalStateException("Unable to parse URI " + namespace, e);
-        }
-        return namespaceURI;
+        // May throw IllegalArgumentException, but that should never happen, as the namespace comes from parsed XML
+        return URI.create(namespace);
     }
 
     //this returns module with the newest revision if more then 1 module with same namespace is found