From 37d5b2c858f9f17bef12c170895e9ac03d50cf05 Mon Sep 17 00:00:00 2001 From: vempo Date: Mon, 23 Oct 2017 15:08:55 +0300 Subject: Finished fixing critical static analysis issues Release all resources such as InputStream in the onboarding code, along with automatic code cleanup and simpification. Change-Id: I0ff0bfe352ff63768d025fbd9dd85b53636e2d49 Issue-ID: SDC-291 Signed-off-by: vempo --- .../sdcrests/action/rest/services/ActionsImpl.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src/main/java/org/openecomp/sdcrests/action/rest/services/ActionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src/main/java/org/openecomp/sdcrests/action/rest/services/ActionsImpl.java index 53ebf0baab..875b51548e 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src/main/java/org/openecomp/sdcrests/action/rest/services/ActionsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/action-library-rest/action-library-rest-services/src/main/java/org/openecomp/sdcrests/action/rest/services/ActionsImpl.java @@ -557,15 +557,13 @@ public class ActionsImpl implements Actions { ACTION_REQUEST_MISSING_MANDATORY_PARAM + ARTIFACT_FILE); } - InputStream artifactInputStream = null; - try { - artifactInputStream = artifactToUpload.getDataHandler().getInputStream(); + try (InputStream artifactInputStream = artifactToUpload.getDataHandler().getInputStream()) { + payload = FileUtils.toByteArray(artifactInputStream); } catch (IOException exception) { LOGGER.error(ACTION_ARTIFACT_READ_FILE_ERROR, exception); throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, ACTION_ARTIFACT_READ_FILE_ERROR); } - payload = FileUtils.toByteArray(artifactInputStream); //Validate Artifact size if (payload != null && payload.length > MAX_ACTION_ARTIFACT_SIZE) { throw new ActionException(ACTION_ARTIFACT_TOO_BIG_ERROR_CODE, ACTION_ARTIFACT_TOO_BIG_ERROR); @@ -761,15 +759,14 @@ public class ActionsImpl implements Actions { } if (artifactToUpdate != null) { - InputStream artifactInputStream = null; - try { - artifactInputStream = artifactToUpdate.getDataHandler().getInputStream(); + + try (InputStream artifactInputStream = artifactToUpdate.getDataHandler().getInputStream()) { + payload = FileUtils.toByteArray(artifactInputStream); } catch (IOException exception) { LOGGER.error(ACTION_ARTIFACT_READ_FILE_ERROR, exception); throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, ACTION_ARTIFACT_READ_FILE_ERROR); } - payload = FileUtils.toByteArray(artifactInputStream); //Validate Artifact size if (payload != null && payload.length > MAX_ACTION_ARTIFACT_SIZE) { throw new ActionException(ACTION_ARTIFACT_TOO_BIG_ERROR_CODE, -- cgit 1.2.3-korg