Fix: sonar related fixes for LISP protocol package
Change-Id: If38ff6be071e1522c925056de44f9ec50910652c
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java
index d6b3c9c..febb41d 100644
--- a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterId.java
@@ -17,6 +17,8 @@
import org.onlab.packet.IpAddress;
import org.onlab.util.Identifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.net.URI;
import java.net.URISyntaxException;
@@ -29,6 +31,7 @@
*/
public final class LispRouterId extends Identifier<IpAddress> {
+ private static final Logger log = LoggerFactory.getLogger(LispRouterId.class);
private static final String SCHEME = "lisp";
private static final IpAddress UNKNOWN = IpAddress.valueOf("0.0.0.0");
@@ -88,6 +91,7 @@
try {
return new URI(SCHEME, ipAddress.toString(), null);
} catch (URISyntaxException e) {
+ log.warn("Failed to parse the IP address.", e);
return null;
}
}
diff --git a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispControllerBootstrap.java b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispControllerBootstrap.java
index 449983a..c529123 100644
--- a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispControllerBootstrap.java
+++ b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispControllerBootstrap.java
@@ -125,9 +125,9 @@
try {
eventLoopGroup = new EpollEventLoopGroup();
channelClass = EpollDatagramChannel.class;
- } catch (Throwable e) {
+ } catch (RuntimeException e) {
log.debug("Failed to initialize native (epoll) transport. "
- + "Reason: {}. Proceeding with NIO event group.", e.getMessage());
+ + "Reason: {}. Proceeding with NIO event group.", e);
}
eventLoopGroup = new NioEventLoopGroup();
channelClass = NioDatagramChannel.class;
diff --git a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispMapResolver.java b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispMapResolver.java
index af7fa20..2436dd7 100644
--- a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispMapResolver.java
+++ b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/impl/LispMapResolver.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.lisp.ctl.impl;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.onosproject.lisp.msg.protocols.DefaultLispEncapsulatedControl.DefaultEcmBuilder;
import org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder;
@@ -100,7 +101,7 @@
} else {
- if (mapReplyRecords.size() > 0) {
+ if (!mapReplyRecords.isEmpty()) {
List<LispMessage> mapReplies = Lists.newArrayList();
@@ -125,7 +126,7 @@
return mapReplies;
}
- if (mapRequestRecords.size() > 0) {
+ if (!mapRequestRecords.isEmpty()) {
List<LispMessage> ecms = Lists.newArrayList();
@@ -146,7 +147,7 @@
return ecms;
}
}
- return null;
+ return ImmutableList.of();
}
/**
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationConfig.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationConfig.java
index b527c9c..afd3e1a 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationConfig.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationConfig.java
@@ -75,8 +75,13 @@
/**
* Prevents object instantiation from external.
*/
- private static class SingletonHelper {
+ private static final class SingletonHelper {
+ private static final String ILLEGAL_ACCESS_MSG = "Should not instantiate this class.";
private static final LispAuthenticationConfig INSTANCE =
- new LispAuthenticationConfig();
+ new LispAuthenticationConfig();
+
+ private SingletonHelper() {
+ throw new IllegalAccessError(ILLEGAL_ACCESS_MSG);
+ }
}
}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispEncapsulatedControl.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispEncapsulatedControl.java
index e615810..67fcc9b 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispEncapsulatedControl.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispEncapsulatedControl.java
@@ -183,8 +183,6 @@
private static final int SECURITY_INDEX = 3;
private static final int RESERVED_SKIP_LENGTH = 3;
- private static final int UDP_HEADER_LENGTH = 8;
- private static final short HEADER_LENGTH_MASK = 0xf;
@Override
public LispEncapsulatedControl readFrom(ByteBuf byteBuf) throws
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
index 7af4fa0..43d90f4 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
@@ -301,7 +301,7 @@
@Override
public LispMapRequest build() {
- checkArgument((itrRlocs != null) && (itrRlocs.size() > 0), "Must have an ITR RLOC entry");
+ checkArgument((itrRlocs != null) && (!itrRlocs.isEmpty()), "Must have an ITR RLOC entry");
return new DefaultLispMapRequest(nonce, sourceEid, itrRlocs, eidRecords,
authoritative, mapDataPresent, probe, smr, pitr, smrInvoked, replyRecord);