From 60be4e21f1ada02fbbdb39cc47ff1c69c098a00a Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 20 Nov 2019 17:32:02 +0000 Subject: Fix Sonar issue Major SmellCode: Replace StringBuffer with StringBuilder Change-Id: I0283e5160e5c1f23423c66110015f18c8163411e Signed-off-by: Vasyl Razinkov Issue-ID: SDC-2670 --- .../executers/ArtifactValidatorExecuter.java | 2 +- .../impl/ComponentInstanceBusinessLogic.java | 4 ++-- .../sdc/be/dao/janusgraph/JanusGraphGenericDao.java | 20 ++++++++++---------- .../sdc/be/dao/jsongraph/utils/IdBuilderUtils.java | 2 +- .../operations/ToscaOperationFacade.java | 2 +- .../operations/NodeTemplateOperationGraphTest.java | 2 +- .../openecomp/sdc/common/util/ValidationUtils.java | 8 ++++---- .../openecomp/sdc/common/test/CommonUtilsTest.java | 2 +- .../sdc/ci/tests/execute/imports/CsarUtilsTest.java | 6 +++--- .../service/CreateServiceMetadataApiTest.java | 2 +- .../ci/tests/utils/general/AtomicOperationUtils.java | 2 +- .../sdc/ci/tests/utils/rest/BaseRestUtils.java | 2 +- .../sdc/webseal/simulator/RequestsClient.java | 2 +- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java index de19d09319..33cf9d46da 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java @@ -134,7 +134,7 @@ public class ArtifactValidatorExecuter{ try { // "service name, service id, state, version for(Component component: components ){ - StringBuffer sb = new StringBuffer(component.getName()); + StringBuilder sb = new StringBuilder(component.getName()); sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID()).append(",").append(component.getLifecycleState()).append(",").append(component.getVersion()); sb.append("\n"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index fd2af0bb7c..040c460ffc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -1828,7 +1828,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { String newValue, Component containerComponent, ComponentInstance foundResourceInstance, String capabilityType, String capabilityName) { String componentInstanceUniqueId = foundResourceInstance.getUniqueId(); - StringBuffer sb = new StringBuffer(componentInstanceUniqueId); + StringBuilder sb = new StringBuilder(componentInstanceUniqueId); sb.append(ModelConverter.CAP_PROP_DELIM).append(property.getOwnerId()).append(ModelConverter.CAP_PROP_DELIM) .append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName); String capKey = sb.toString(); @@ -1858,7 +1858,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } else { propOwner = foundResourceInstance.getSourceModelUid(); } - StringBuffer sb = new StringBuffer(componentInstanceUniqueId); + StringBuilder sb = new StringBuilder(componentInstanceUniqueId); sb.append(ModelConverter.CAP_PROP_DELIM).append(propOwner).append(ModelConverter.CAP_PROP_DELIM) .append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java index 591d7f32d7..f679a5c103 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java @@ -1246,16 +1246,16 @@ public class JanusGraphGenericDao { public JanusGraphOperationStatus lockElement(String id, NodeTypeEnum type) { - StringBuffer lockId = new StringBuffer(LOCK_NODE_PREFIX); + StringBuilder lockId = new StringBuilder(LOCK_NODE_PREFIX); lockId.append(type.getName()).append("_").append(id); return lockNode(lockId.toString()); } public JanusGraphOperationStatus lockElement(GraphNode node) { - StringBuffer lockId = createLockElementId(node); + String lockId = createLockElementId(node); - return lockNode(lockId.toString()); + return lockNode(lockId); } private JanusGraphOperationStatus lockNode(String lockId) { @@ -1416,12 +1416,12 @@ public class JanusGraphGenericDao { * @return */ public JanusGraphOperationStatus releaseElement(GraphNode node) { - StringBuffer lockId = createLockElementId(node); + String lockId = createLockElementId(node); return unlockNode(lockId); } - private JanusGraphOperationStatus unlockNode(StringBuffer lockId) { + private JanusGraphOperationStatus unlockNode(String lockId) { GraphNodeLock lockNode = new GraphNodeLock(lockId.toString()); Either lockNodeNew = deleteNode(lockNode, GraphNodeLock.class); @@ -1437,15 +1437,15 @@ public class JanusGraphGenericDao { } public JanusGraphOperationStatus releaseElement(String id, NodeTypeEnum type) { - StringBuffer lockId = new StringBuffer(LOCK_NODE_PREFIX); + StringBuilder lockId = new StringBuilder(LOCK_NODE_PREFIX); lockId.append(type.getName()).append("_").append(id); - return unlockNode(lockId); + return unlockNode(lockId.toString()); } - private StringBuffer createLockElementId(GraphNode node) { - StringBuffer lockId = new StringBuffer(LOCK_NODE_PREFIX); + private String createLockElementId(GraphNode node) { + StringBuilder lockId = new StringBuilder(LOCK_NODE_PREFIX); lockId.append(node.getLabel()).append("_").append(node.getUniqueId()); - return lockId; + return lockId.toString(); } public Either, JanusGraphOperationStatus> getChild(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class clazz) { diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/utils/IdBuilderUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/utils/IdBuilderUtils.java index 2d2d9b8962..acd6969a71 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/utils/IdBuilderUtils.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/utils/IdBuilderUtils.java @@ -28,7 +28,7 @@ public class IdBuilderUtils { private static String DOT = "."; public static String generateChildId(String componentId, VertexTypeEnum type){ - StringBuffer sb = new StringBuffer(componentId); + StringBuilder sb = new StringBuilder(componentId); sb.append(DOT).append(type.getName()); return sb.toString(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index ab08f5c339..d5e0675203 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -1365,7 +1365,7 @@ public class ToscaOperationFacade { propOwner = fetchedCIOptional.get().getSourceModelUid(); } StorageOperationStatus status; - StringBuffer sb = new StringBuffer(componentInstanceId); + StringBuilder sb = new StringBuilder(componentInstanceId); sb.append(ModelConverter.CAP_PROP_DELIM).append(propOwner).append(ModelConverter.CAP_PROP_DELIM) .append(capabilityDefinition.getType()).append(ModelConverter.CAP_PROP_DELIM).append(capabilityDefinition.getName()); String capKey = sb.toString(); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java index 390e27ee0b..9c9194828e 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java @@ -211,7 +211,7 @@ public class NodeTemplateOperationGraphTest extends ModelTestBase{ } private String buildInstanceId(int originIndex, int insIndex) { - StringBuffer sb = new StringBuffer("instanceId_"); + StringBuilder sb = new StringBuilder("instanceId_"); sb.append(originIndex).append("-").append(insIndex); return sb.toString(); } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java b/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java index 6633148485..988f215a72 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java @@ -383,7 +383,7 @@ public class ValidationUtils { public static String normaliseComponentName(String name) { String[] split = splitComponentName(name); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String splitElement : split) { sb.append(splitElement); } @@ -393,7 +393,7 @@ public class ValidationUtils { public static String normalizeComponentInstanceName(String name) { String[] split = splitComponentInstanceName(name); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String splitElement : split) { sb.append(splitElement); } @@ -415,7 +415,7 @@ public class ValidationUtils { public static String convertToSystemName(String name) { String[] split = splitComponentName(name); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String splitElement : split) { String capitalize = WordUtils.capitalize(splitElement); sb.append(capitalize); @@ -531,7 +531,7 @@ public class ValidationUtils { public static String normaliseProductName(String name) { String[] split = splitComponentName(PRODUCT_NAME_DELIMETER_PATTERN, name); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String splitElement : split) { sb.append(splitElement); } diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java index 9806bffc5e..fadb9d47aa 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java @@ -475,7 +475,7 @@ public class CommonUtilsTest { @Test public void yamlValidTest() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("key: \"!@;/?:&=+$,_.~*'()[]\""); byte[] payload = sb.toString().getBytes(); diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java index 56502757de..fd1703bfcb 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java @@ -153,7 +153,7 @@ public class CsarUtilsTest extends ComponentBaseTest { String resourceYaml = null; byte[] buffer = new byte[1024]; ZipEntry nextEntry = zip.getNextEntry(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int len; while ((len = zip.read(buffer)) > 0) { @@ -203,7 +203,7 @@ public class CsarUtilsTest extends ComponentBaseTest { String resourceYaml = null; byte[] buffer = new byte[1024]; ZipEntry nextEntry = zip.getNextEntry(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int len; while ((len = zip.read(buffer)) > 0) { @@ -311,7 +311,7 @@ public class CsarUtilsTest extends ComponentBaseTest { String resourceYaml = null; byte[] buffer = new byte[1024]; ZipEntry nextEntry = zip.getNextEntry(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int len; while ((len = zip.read(buffer)) > 0) { diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/service/CreateServiceMetadataApiTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/service/CreateServiceMetadataApiTest.java index 071624676f..eabf057715 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/service/CreateServiceMetadataApiTest.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/service/CreateServiceMetadataApiTest.java @@ -631,7 +631,7 @@ public class CreateServiceMetadataApiTest extends ComponentBaseTest { // fill new service details ServiceReqDetails serviceDetails = ElementFactory.getDefaultService(); - StringBuffer tagBuffer = new StringBuffer(); + StringBuilder tagBuffer = new StringBuilder(); for (int i = 0; i < 1025; i++) { tagBuffer.append("a"); } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/AtomicOperationUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/AtomicOperationUtils.java index 8e5079db92..43c93e47a6 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/AtomicOperationUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/general/AtomicOperationUtils.java @@ -774,7 +774,7 @@ public final class AtomicOperationUtils { // Get the CSARs path String realFilePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "CI" + File.separator + "csars" ; if (filePath != null && filePath.length > 0) { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); for(String currStr: filePath){ result.append(currStr); } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java index 56859ff56a..b8ec35f0ff 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/BaseRestUtils.java @@ -179,7 +179,7 @@ public class BaseRestUtils extends BaseValidationUtils { int statusCode = response.getStatusLine().getStatusCode(); postResponse.setErrorCode(statusCode); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); try { BufferedReader in = new BufferedReader(new InputStreamReader(responseEntity.getContent())); String inputLine; diff --git a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java index 9ce20939f5..d03b93c727 100644 --- a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java +++ b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java @@ -117,7 +117,7 @@ public class RequestsClient extends HttpServlet { // logger.debug("Send POST http request, url: {}", url); // logger.debug("Response Code: {}", responseCode); - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); try { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; -- cgit 1.2.3-korg