Enable spotbugs and fix spotbugs warns

Issue-ID: CPS-159
Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech>
Change-Id: Iee572fd740689a172ca599123b0751b5e909223a
diff --git a/cps-parent/pom.xml b/cps-parent/pom.xml
index d3470df..08b1883 100644
--- a/cps-parent/pom.xml
+++ b/cps-parent/pom.xml
@@ -240,7 +240,7 @@
                         <!-- Reports all bugs (other values are medium and max) -->
                         <threshold>Low</threshold>
                         <!-- Build doesn't fail if problems are found -->
-                        <failOnError>false</failOnError>
+                        <failOnError>true</failOnError>
                         <!-- References the excluded rules -->
                         <excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
                         <!-- Produces XML report -->
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java b/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
index 0c527a5..c53d1a4 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
@@ -19,10 +19,12 @@
 
 package org.onap.cps.rest.utils;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.opendaylight.yangtools.yang.common.YangConstants.RFC6020_YANG_FILE_EXTENSION;
 
 import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
@@ -47,7 +49,7 @@
     }
 
     private static String extractYangResourceName(final MultipartFile multipartFile) {
-        final String fileName = multipartFile.getOriginalFilename();
+        final String fileName = checkNotNull(multipartFile.getOriginalFilename(), "Missing filename.");
         if (!fileName.endsWith(RFC6020_YANG_FILE_EXTENSION)) {
             throw new ModelValidationException("Unsupported file type.",
                 String.format("Filename %s does not end with '%s'", fileName, RFC6020_YANG_FILE_EXTENSION));
@@ -57,7 +59,7 @@
 
     private static String extractYangResourceContent(final MultipartFile multipartFile) {
         try {
-            return new String(multipartFile.getBytes());
+            return new String(multipartFile.getBytes(), StandardCharsets.UTF_8);
         } catch (final IOException e) {
             throw new CpsException("Cannot read the resource file.", e.getMessage(), e);
         }
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index 23a3843..0832930 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -21,6 +21,7 @@
 package org.onap.cps.spi.impl;
 
 import com.google.common.collect.ImmutableSet;
+import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -76,7 +77,7 @@
                 final YangResource yangResource = new YangResource();
                 yangResource.setName(entry.getKey());
                 yangResource.setContent(entry.getValue());
-                yangResource.setChecksum(DigestUtils.md5DigestAsHex(entry.getValue().getBytes()));
+                yangResource.setChecksum(DigestUtils.md5DigestAsHex(entry.getValue().getBytes(StandardCharsets.UTF_8)));
                 return yangResource;
             })
             .collect(Collectors.toMap(
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
index aa198a9..8989e6c 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
@@ -20,6 +20,7 @@
 
 package org.onap.cps.spi.model;
 
+import java.io.Serializable;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -29,7 +30,9 @@
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class ModuleReference {
+public class ModuleReference implements Serializable {
+
+    private static final long serialVersionUID = 1L;
 
     private String name;
     private String namespace;
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
index 8743b7d..8077ed7 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
@@ -103,7 +103,7 @@
         } else if (normalizedNode instanceof LeafSetNode) {
             inspectLeafList(currentFragment, (LeafSetNode) normalizedNode);
         } else {
-            log.warn("Cannot normalize " + normalizedNode.getClass());
+            log.warn("Cannot normalize {}", normalizedNode.getClass());
         }
     }
 
diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
index ae0f2cd..b1462cd 100644
--- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
@@ -19,11 +19,14 @@
 
 package org.onap.cps.yang;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableMap;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -140,8 +143,9 @@
             .collect(Collectors.toList());
     }
 
-    private static YangTextSchemaSource toYangTextSchemaSource(final String sourceName, final String source) {
-        final Map.Entry<String, String> sourceNameParsed = YangNames.parseFilename(sourceName);
+    private static YangTextSchemaSource toYangTextSchemaSource(final String sourceName,
+            final String source) {
+        final Map.Entry<String, String> sourceNameParsed = checkNotNull(YangNames.parseFilename(sourceName));
         final RevisionSourceIdentifier revisionSourceIdentifier = RevisionSourceIdentifier
             .create(sourceNameParsed.getKey(), Revision.ofNullable(sourceNameParsed.getValue()));
 
@@ -154,7 +158,7 @@
 
             @Override
             public InputStream openStream() {
-                return new ByteArrayInputStream(source.getBytes());
+                return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8));
             }
         };
     }