Fix sonar issues in gson superclasses
Fixing some of the issues necessitated the use of generic/raw types.
Removed version from assertj in pom.
Removed trailing spaces.
Change-Id: I76e0a05ca06c103ccc876675be04a4ab5e4de5ea
Issue-ID: POLICY-1428
Signed-off-by: Jim Hahn <jrh3@att.com>
diff --git a/gson/pom.xml b/gson/pom.xml
index 3b9983f..110fccb 100644
--- a/gson/pom.xml
+++ b/gson/pom.xml
@@ -55,7 +55,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
index 2112c97..66475e3 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java
@@ -80,7 +80,7 @@
@Override
public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
- throws IOException, WebApplicationException {
+ throws IOException {
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8)) {
Type jsonType = (type.equals(genericType) ? type : genericType);
@@ -107,8 +107,11 @@
String subtype = mediaType.getSubtype();
- return "json".equalsIgnoreCase(subtype) || subtype.endsWith("+json") || "javascript".equals(subtype)
- || "x-javascript".equals(subtype) || "x-json".equals(subtype);
+ if ("json".equalsIgnoreCase(subtype) || "javascript".equals(subtype)) {
+ return true;
+ }
+
+ return subtype.endsWith("+json") || "x-json".equals(subtype) || "x-javascript".equals(subtype);
}
@Override
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
index b4ef53f..94091c7 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
@@ -116,8 +116,9 @@
}
ConvInfo wtr = writer;
- TypeAdapter<Object> conv =
- (TypeAdapter<Object>) (wtr.clazz == clazz ? wtr.getConverter() : gson.getAdapter(clazz));
+
+ @SuppressWarnings("rawtypes")
+ TypeAdapter conv = (wtr.clazz == clazz ? wtr.getConverter() : gson.getAdapter(clazz));
return conv.toJsonTree(object);
}
@@ -305,29 +306,33 @@
/**
* Type on which the converter works.
*/
- private TypeToken<?> type;
+ @SuppressWarnings("rawtypes")
+ private TypeToken type;
/**
* Class of object on which the converter works.
*/
- private Class<?> clazz;
+ @SuppressWarnings("rawtypes")
+ private Class clazz;
/**
* Converter to use, initialized lazily.
*/
- private volatile TypeAdapter<?> conv = null;
+ @SuppressWarnings("rawtypes")
+ private volatile TypeAdapter conv = null;
/**
* Constructs the object.
*
* @param type type of object to be converted
*/
- public ConvInfo(TypeToken<?> type) {
+ public ConvInfo(@SuppressWarnings("rawtypes") TypeToken type) {
this.type = type;
this.clazz = type.getRawType();
}
- public final TypeAdapter<?> getConverter() {
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public final TypeAdapter getConverter() {
if (conv == null) {
// race condition here, but it's ok to overwrite a previous value
this.conv = gson.getAdapter(type);
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java
index e985d98..89e4f89 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java
@@ -122,7 +122,7 @@
* @return the property names having a non-null value
*/
private List<String> getNonNull(Map<String, Object> props) {
- List<String> lst = new ArrayList<String>(props.size());
+ List<String> lst = new ArrayList<>(props.size());
for (Entry<String, Object> ent : props.entrySet()) {
if (ent.getValue() != null) {
@@ -162,7 +162,7 @@
*/
@SuppressWarnings("unchecked")
private <T> List<T> getProps(Class<T> clazz, Collection<Object> values) {
- List<T> lst = new ArrayList<T>(values.size());
+ List<T> lst = new ArrayList<>(values.size());
for (Object val : values) {
if (val != null && val.getClass() == clazz) {
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java
index f297586..4bf6e0c 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java
@@ -25,10 +25,9 @@
/**
* Super class of all de-serializers.
*/
+@FunctionalInterface
public interface Deserializer {
- String INVOKE_ERR = "cannot invoke method to deserialize: ";
-
/**
* Gets an value from a tree, converts it, and puts it into a target object.
*
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java
index 2e2782a..254a5fe 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java
@@ -25,6 +25,7 @@
/**
* Super class of all serializers.
*/
+@FunctionalInterface
public interface Serializer {
/**