From 02cd5dcdaa63858ebce30cfe4eba784b6e167e25 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Mon, 13 Jun 2016 15:09:35 +0200 Subject: [PATCH] Bug 5529 - Restconf M5 - Clean-up sonar issues Remove critical issues Change-Id: Ie14934864976b5f9496af836a81293f052f4666d Signed-off-by: Ivan Hrasko --- .../restconf/impl/RestconfDocumentedException.java | 5 +++-- .../netconf/sal/restconf/impl/RestconfError.java | 12 ++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfDocumentedException.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfDocumentedException.java index 47710708f6..da3672a2b4 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfDocumentedException.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfDocumentedException.java @@ -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))); } /** diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfError.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfError.java index c86706cedd..316e766bd3 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfError.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfError.java @@ -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 = "" + rpcError.getSeverity().toString().toLowerCase() + ""; } -- 2.36.6