SONAR suggestion - log exceptions, don't print stack traces
Change-Id: I4814a0662912706df005972d44c48a7db39ecd50
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisConfig.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisConfig.java
index b21c5f6..9d188dd 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisConfig.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisConfig.java
@@ -399,7 +399,7 @@
try {
asnPath.add(path.getInt(i));
} catch (JSONException e) {
- e.printStackTrace();
+ log.warn("checkPath", e);
}
}
// reverse the list to get path starting from origin
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisDeaggregatorImpl.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisDeaggregatorImpl.java
index 32dbb8a..d9141f4 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisDeaggregatorImpl.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/ArtemisDeaggregatorImpl.java
@@ -23,7 +23,6 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.CharsetUtil;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -395,8 +394,7 @@
ByteBuf buffer = Unpooled.copiedBuffer(jsonInString, CharsetUtil.UTF_8);
ctx.writeAndFlush(buffer);
} catch (JsonProcessingException e) {
- e.printStackTrace();
- log.warn(ExceptionUtils.getFullStackTrace(e));
+ log.warn("processMoasPacket()", e);
}
remoteTunnelIp = IpAddress.valueOf(msg.getLocalIp());
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientHandler.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientHandler.java
index 58954d9..b7cb3c5 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientHandler.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientHandler.java
@@ -24,7 +24,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.artemis.ArtemisPacketProcessor;
@@ -69,8 +68,7 @@
ByteBuf buffer = Unpooled.copiedBuffer(jsonInString, CharsetUtil.UTF_8);
ctx.writeAndFlush(buffer);
} catch (JsonProcessingException e) {
- e.printStackTrace();
- log.warn(ExceptionUtils.getFullStackTrace(e));
+ log.warn("channelActive()", e);
}
}
@@ -87,8 +85,7 @@
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
- log.error(ExceptionUtils.getFullStackTrace(cause));
- cause.printStackTrace();
+ log.error("exceptionCaught()", cause);
ctx.close();
}
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerHandler.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerHandler.java
index d140416..6a6a0ab 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerHandler.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerHandler.java
@@ -22,7 +22,6 @@
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.onlab.packet.IpAddress;
import org.onosproject.artemis.impl.objects.ArtemisMessage;
import org.slf4j.Logger;
@@ -77,8 +76,7 @@
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
- log.error(ExceptionUtils.getFullStackTrace(cause));
- cause.printStackTrace();
+ log.error("exceptionCaught()", cause);
ctx.close();
}
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/ExaBgpMonitors.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/ExaBgpMonitors.java
index 5fb9be4..d645360 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/ExaBgpMonitors.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/ExaBgpMonitors.java
@@ -54,7 +54,7 @@
socket.emit("exa_subscribe", parameters);
} catch (JSONException e) {
- e.printStackTrace();
+ log.warn("onConenct()", e);
}
}
@@ -88,7 +88,7 @@
packetProcessor.processMonitorPacket(message);
}
} catch (JSONException e) {
- e.printStackTrace();
+ log.warn("onExaMessage()", e);
}
}
@@ -112,7 +112,7 @@
this.socket.on(Socket.EVENT_PING, args -> socket.emit("pong"));
this.socket.on("exa_message", this::onExaMessage);
} catch (URISyntaxException e) {
- e.printStackTrace();
+ log.warn("startMonitor()", e);
}
this.socket.connect();
}
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/RipeMonitors.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/RipeMonitors.java
index e848875..52025c9 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/RipeMonitors.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/monitors/RipeMonitors.java
@@ -17,7 +17,6 @@
import io.socket.client.IO;
import io.socket.client.Socket;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.onlab.packet.IpPrefix;
@@ -63,7 +62,7 @@
socket.emit("ris_subscribe", parameters);
} catch (JSONException e) {
- e.printStackTrace();
+ log.warn("onConnect()", e);
}
}
@@ -110,8 +109,7 @@
packetProcessor.processMonitorPacket(message);
}
} catch (JSONException e) {
- log.error(ExceptionUtils.getFullStackTrace(e));
- e.printStackTrace();
+ log.error("onRisMessage()", e);
}
socket.emit("ping");
}
@@ -129,8 +127,7 @@
this.socket.on(Socket.EVENT_PONG, args -> socket.emit("ping"));
this.socket.on("ris_message", this::onRisMessage);
} catch (URISyntaxException e) {
- log.error(ExceptionUtils.getFullStackTrace(e));
- e.printStackTrace();
+ log.error("startMonitor()", e);
}
this.socket.connect();
diff --git a/apps/castor/src/main/java/org/onosproject/castor/CastorWebResource.java b/apps/castor/src/main/java/org/onosproject/castor/CastorWebResource.java
index 409216b..37630cf 100644
--- a/apps/castor/src/main/java/org/onosproject/castor/CastorWebResource.java
+++ b/apps/castor/src/main/java/org/onosproject/castor/CastorWebResource.java
@@ -20,6 +20,7 @@
import org.onlab.packet.IpAddress;
import org.onosproject.rest.AbstractWebResource;
+import java.io.IOException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -88,8 +89,7 @@
get(ArpService.class).createArp(peer);
arpResult = ", ARP packet sent, MAC was not known";
}
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
String result = "Unable to process due to some reason, Try again";
ObjectNode node = mapper().createObjectNode().put("response", result);
return ok(node).build();
@@ -117,8 +117,7 @@
ObjectMapper mapper = new ObjectMapper();
Peer peer = mapper.readValue(incomingData, Peer.class);
get(ConnectivityManagerService.class).deletePeer(peer);
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
return Response.status(500).entity("Unable to delete the peer").build();
}
String result = "Peer Deleted";
@@ -143,8 +142,7 @@
ObjectMapper mapper = new ObjectMapper();
Peer peer = mapper.readValue(incomingData, Peer.class);
get(ConnectivityManagerService.class).start(peer);
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
return Response.status(500).entity("Unable to add the route server").build();
}
String result = "Server Entered";
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
index 0cb3468..09a118c 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
@@ -648,7 +648,7 @@
recordSemaphore.release();
}
} catch (InterruptedException e) {
- e.printStackTrace();
+ Thread.currentThread().interrupt();
}
}
@@ -807,7 +807,7 @@
recordSemaphore.release();
}
} catch (InterruptedException e) {
- e.printStackTrace();
+ Thread.currentThread().interrupt();
}
}
diff --git a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/impl/KafkaStorageManager.java b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/impl/KafkaStorageManager.java
index 66bfc18..19e58ca 100644
--- a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/impl/KafkaStorageManager.java
+++ b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/impl/KafkaStorageManager.java
@@ -77,9 +77,9 @@
try {
task = future.get();
} catch (InterruptedException e) {
- e.printStackTrace();
+ Thread.currentThread().interrupt();
} catch (ExecutionException e) {
- e.printStackTrace();
+ log.warn("consumeEvent()", e);
}
if (task != null) {
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
index 92043d5..33b52a4 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
@@ -194,7 +194,7 @@
return netconfTranslator.editDeviceConfig(
deviceId, builder.build(), operationType);
} catch (IOException e) {
- e.printStackTrace();
+ log.debug("parseAndEdit()", e);
return false;
}
}
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
index c563204..f663fd0 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
@@ -93,8 +93,8 @@
@Component(immediate = true)
public class NetconfTranslatorImpl implements NetconfTranslator {
- private final Logger log = LoggerFactory
- .getLogger(getClass());
+ private static final Logger log = LoggerFactory
+ .getLogger(NetconfTranslator.class);
private NodeId localNodeId;
@@ -354,7 +354,7 @@
try {
rIdBldr = rid.copyBuilder();
} catch (CloneNotSupportedException e) {
- e.printStackTrace();
+ log.debug("clone not supported", e);
}
} else {
rIdBldr.addBranchPointSchema("/", null);
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/Utils.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/Utils.java
index cb8e89c..5e06420 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/Utils.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/Utils.java
@@ -108,7 +108,7 @@
try {
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {
- e.printStackTrace();
+ return "";
}
// Need to omit the xml header and set indent to 4
@@ -122,7 +122,7 @@
try {
transformer.transform(xmlInput, xmlOutput);
} catch (TransformerException e) {
- e.printStackTrace();
+ return "";
}
}
return xmlOutput.getWriter().toString();
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/Ea1000DeviceDescription.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/Ea1000DeviceDescription.java
index 34274e2..faf2007 100644
--- a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/Ea1000DeviceDescription.java
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/Ea1000DeviceDescription.java
@@ -109,9 +109,7 @@
latitudeStr = augmentedSystem.latitude().toPlainString();
}
} catch (NetconfException e) {
- log.error("Unable to retrieve init data from device: " + handler().data().deviceId().toString()
- + " Error: " + e.getMessage());
- e.printStackTrace();
+ log.error("Unable to retrieve init data from device: " + handler().data().deviceId().toString(), e);
}
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/VirtualProviderManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/VirtualProviderManager.java
index a103024..77cac78 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/VirtualProviderManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/provider/VirtualProviderManager.java
@@ -25,6 +25,8 @@
import org.onosproject.incubator.net.virtual.provider.VirtualProviderService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.HashSet;
@@ -47,6 +49,7 @@
private final Map<ProviderId, VirtualProviderService> servicesWithProvider = new HashMap<>();
private final Map<String, VirtualProvider> providersByScheme = new HashMap<>();
private final Map<NetworkId, Set<VirtualProviderService>> servicesByNetwork = new HashMap<>();
+ private static Logger log = LoggerFactory.getLogger(VirtualProviderManager.class);
@Override
public synchronized void registerProvider(VirtualProvider virtualProvider) {
@@ -160,7 +163,7 @@
try {
return Class.forName(pramType);
} catch (ClassNotFoundException e) {
- e.printStackTrace();
+ log.warn("getProviderClass()", e);
}
return null;
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfStreamThread.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfStreamThread.java
index e80e214..12eedfa 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfStreamThread.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfStreamThread.java
@@ -243,7 +243,7 @@
try {
bufferReader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
} catch (UnsupportedEncodingException e) {
- e.printStackTrace();
+ throw new IllegalStateException(e);
}
}
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
index c546c49..5e5ba37 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
@@ -377,7 +377,7 @@
}
} }, new java.security.SecureRandom());
} catch (NoSuchAlgorithmException | KeyManagementException e) {
- e.printStackTrace();
+ throw new IllegalStateException(e);
}
return ClientBuilder.newBuilder().sslContext(sslcontext).hostnameVerifier((s1, s2) -> true).build();