Bug 5529 - Restconf M5 - Clean-up sonar issues 36/40236/4
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Mon, 13 Jun 2016 13:09:35 +0000 (15:09 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 15 Jun 2016 06:47:35 +0000 (06:47 +0000)
Remove critical issues

Change-Id: Ie14934864976b5f9496af836a81293f052f4666d
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfDocumentedException.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfError.java

index 47710708f6236f6b284313b3dcab009982b93a71..da3672a2b4334297cabd07d9b8b362cb20f2f739 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.netconf.sal.restconf.impl;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import java.util.Collection;
@@ -58,7 +59,7 @@ public class RestconfDocumentedException extends WebApplicationException {
      *            The underlying exception cause.
      */
     public RestconfDocumentedException(String message, ErrorType errorType, ErrorTag errorTag, Throwable cause) {
-        this(cause, new RestconfError(errorType, errorTag, message, null, RestconfError.toErrorInfo(cause)));
+        this(cause, new RestconfError(errorType, errorTag, message, null, Throwables.getStackTraceAsString(cause)));
     }
 
     /**
@@ -86,7 +87,7 @@ public class RestconfDocumentedException extends WebApplicationException {
      */
     public RestconfDocumentedException(String message, Throwable cause) {
         this(cause, new RestconfError(RestconfError.ErrorType.APPLICATION, RestconfError.ErrorTag.OPERATION_FAILED,
-                message, null, RestconfError.toErrorInfo(cause)));
+                message, null, Throwables.getStackTraceAsString(cause)));
     }
 
     /**
index c86706cedd705163060ffcbebaa5a29e03199812..316e766bd34bfa3d18dfc80ad041342a8cbcf59a 100644 (file)
@@ -8,8 +8,7 @@
 package org.opendaylight.netconf.sal.restconf.impl;
 
 import com.google.common.base.Preconditions;
-import java.io.PrintWriter;
-import java.io.StringWriter;
+import com.google.common.base.Throwables;
 import org.opendaylight.yangtools.yang.common.RpcError;
 
 /**
@@ -99,15 +98,8 @@ public class RestconfError {
     private final String errorInfo;
     private final String errorAppTag;
     private final String errorMessage;
-
     // TODO: Add in the error-path concept as defined in the ietf draft.
 
-    static String toErrorInfo(Throwable cause) {
-        StringWriter writer = new StringWriter();
-        cause.printStackTrace(new PrintWriter(writer));
-        return writer.toString();
-    }
-
     /**
      * Constructs a RestConfError
      *
@@ -180,7 +172,7 @@ public class RestconfError {
         String errorInfo = null;
         if (rpcError.getInfo() == null) {
             if (rpcError.getCause() != null) {
-                errorInfo = toErrorInfo(rpcError.getCause());
+                errorInfo = Throwables.getStackTraceAsString(rpcError.getCause());
             } else if (rpcError.getSeverity() != null) {
                 errorInfo = "<severity>" + rpcError.getSeverity().toString().toLowerCase() + "</severity>";
             }