From 1d0aaaa5b31719c1718700bb0d1a99c413fd513c Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 6 May 2021 11:28:53 -0400 Subject: Fix sonars in policy-common Fixed sonars: - use "var" instead of actual type name - re-interrupt threads - use rej2 split() instead of String split() Issue-ID: POLICY-3285 Change-Id: I82261e0b8a53ee5c5264556fbf5cec37454f014e Signed-off-by: Jim Hahn --- .../main/java/org/onap/policy/common/gson/DoubleConverter.java | 6 +++--- .../java/org/onap/policy/common/gson/GsonMessageBodyHandler.java | 4 ++-- .../org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java | 2 +- .../org/onap/policy/common/gson/JacksonFieldAdapterFactory.java | 4 ++-- .../org/onap/policy/common/gson/JacksonMethodAdapterFactory.java | 4 ++-- .../org/onap/policy/common/gson/MapDoubleAdapterFactory.java | 4 ++-- .../org/onap/policy/common/gson/internal/JacksonTypeAdapter.java | 9 ++++----- 7 files changed, 16 insertions(+), 17 deletions(-) (limited to 'gson') diff --git a/gson/src/main/java/org/onap/policy/common/gson/DoubleConverter.java b/gson/src/main/java/org/onap/policy/common/gson/DoubleConverter.java index 81803ff2..cbf5d0e7 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/DoubleConverter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/DoubleConverter.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,7 +98,7 @@ public class DoubleConverter { } Double num = (Double) value; - long longval = num.longValue(); + var longval = num.longValue(); if (Double.compare(num.doubleValue(), longval) != 0) { // it isn't integral - return unchanged value @@ -106,7 +106,7 @@ public class DoubleConverter { } // it's integral - determine if it's an integer or a long - int intval = (int) longval; + var intval = (int) longval; if (intval == longval) { return intval; 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 df3def3c..a8017d22 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 @@ -116,7 +116,7 @@ public class GsonMessageBodyHandler implements MessageBodyReader, Messag public void writeTo(Object object, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8)) { + try (var writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8)) { Type jsonType = (type.equals(genericType) ? type : genericType); gson.toJson(object, jsonType, writer); } @@ -152,7 +152,7 @@ public class GsonMessageBodyHandler implements MessageBodyReader, Messag public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - try (InputStreamReader streamReader = new InputStreamReader(entityStream, StandardCharsets.UTF_8)) { + try (var streamReader = new InputStreamReader(entityStream, StandardCharsets.UTF_8)) { Type jsonType = (type.equals(genericType) ? type : genericType); return gson.fromJson(streamReader, jsonType); } diff --git a/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java b/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java index c63b03c3..c38a3e9b 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java @@ -47,7 +47,7 @@ public class InstantAsMillisTypeAdapter extends TypeAdapter { in.nextNull(); return null; } else { - long millis = in.nextLong(); + var millis = in.nextLong(); return Instant.ofEpochMilli(millis); } } diff --git a/gson/src/main/java/org/onap/policy/common/gson/JacksonFieldAdapterFactory.java b/gson/src/main/java/org/onap/policy/common/gson/JacksonFieldAdapterFactory.java index 3458a590..18157b03 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/JacksonFieldAdapterFactory.java +++ b/gson/src/main/java/org/onap/policy/common/gson/JacksonFieldAdapterFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ public class JacksonFieldAdapterFactory implements TypeAdapterFactory { return null; } - ClassWalker data = new ClassWalker(); + var data = new ClassWalker(); data.walkClassHierarchy(clazz); if (data.getInProps(Field.class).isEmpty() && data.getOutProps(Field.class).isEmpty()) { diff --git a/gson/src/main/java/org/onap/policy/common/gson/JacksonMethodAdapterFactory.java b/gson/src/main/java/org/onap/policy/common/gson/JacksonMethodAdapterFactory.java index de962316..b7414004 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/JacksonMethodAdapterFactory.java +++ b/gson/src/main/java/org/onap/policy/common/gson/JacksonMethodAdapterFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public class JacksonMethodAdapterFactory implements TypeAdapterFactory { return null; } - ClassWalker data = new ClassWalker(); + var data = new ClassWalker(); data.walkClassHierarchy(clazz); if (data.getInProps(Method.class).isEmpty() && data.getOutProps(Method.class).isEmpty() diff --git a/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java b/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java index 575c41ee..057e97f8 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java +++ b/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,7 +112,7 @@ public class MapDoubleAdapterFactory implements TypeAdapterFactory { @Override public T read(JsonReader in) throws IOException { - T value = delegate.read(in); + var value = delegate.read(in); DoubleConverter.convertFromDouble(value); diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java index 1171fd4d..34d61f47 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ package org.onap.policy.common.gson.internal; import com.google.gson.Gson; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; @@ -78,7 +77,7 @@ public class JacksonTypeAdapter extends TypeAdapter { JsonElement tree = delegate.toJsonTree(value); if (tree.isJsonObject()) { - JsonObject jsonObj = tree.getAsJsonObject(); + var jsonObj = tree.getAsJsonObject(); // serialize each item from the value into the target tree for (Serializer serializer : serializers) { @@ -92,10 +91,10 @@ public class JacksonTypeAdapter extends TypeAdapter { @Override public T read(JsonReader in) throws IOException { JsonElement tree = elementAdapter.read(in); - T object = delegate.fromJsonTree(tree); + var object = delegate.fromJsonTree(tree); if (tree.isJsonObject()) { - JsonObject jsonObj = tree.getAsJsonObject(); + var jsonObj = tree.getAsJsonObject(); // deserialize each item from the tree into the target object for (Deserializer dser : deserializers) { -- cgit 1.2.3-korg