From 72cae8daa32e24c1f50c09fff71ac87d2d6e0a19 Mon Sep 17 00:00:00 2001 From: BAMOE CI Date: Mon, 20 Nov 2023 12:38:42 +0100 Subject: [PATCH] [kie-issues#698] Fix SCA quality issue on generated code --- .../DecisionRestResourceQuarkusTemplate.java | 10 ++++++---- .../DecisionRestResourceSpringTemplate.java | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceQuarkusTemplate.java b/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceQuarkusTemplate.java index 57d3dfcc692..bc71d6ad53e 100644 --- a/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceQuarkusTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceQuarkusTemplate.java @@ -18,6 +18,8 @@ */ package org.kie.dmn.kogito.quarkus.example; +import java.io.InputStream; +import java.util.Objects; import java.util.stream.Collectors; import javax.ws.rs.Consumes; @@ -29,6 +31,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; +import org.kie.dmn.feel.codegen.feel11.CodegenStringUtil; import org.kie.kogito.Application; import org.kie.kogito.dmn.rest.DMNEvaluationErrorException; import org.kie.kogito.dmn.rest.DMNJSONUtils; @@ -70,10 +73,9 @@ public Response dmn($inputType$ variables) { @GET @Produces(MediaType.APPLICATION_XML) public String dmn() throws java.io.IOException { - return new String(org.drools.util.IoUtils. - readBytesFromInputStream(this.getClass() - .getResourceAsStream(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.escapeIdentifier("$modelName$") + - ".dmn_nologic"))); + try (InputStream is = this.getClass().getResourceAsStream(CodegenStringUtil.escapeIdentifier("$modelName$") + ".dmn_nologic")) { + return new String(org.drools.util.IoUtils.readBytesFromInputStream(Objects.requireNonNull(is))); + } } private ResponseBuilder extractContextIfSucceded(KogitoDMNResult result){ diff --git a/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceSpringTemplate.java b/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceSpringTemplate.java index 2bf855cb9c8..27bfc5a33a7 100644 --- a/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceSpringTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-decisions/src/main/resources/class-templates/DecisionRestResourceSpringTemplate.java @@ -18,10 +18,13 @@ */ package org.kie.dmn.kogito.quarkus.example; +import java.io.InputStream; import java.util.AbstractMap.SimpleEntry; import java.util.Map.Entry; +import java.util.Objects; import java.util.stream.Collectors; +import org.kie.dmn.feel.codegen.feel11.CodegenStringUtil; import org.kie.kogito.Application; import org.kie.kogito.dmn.rest.DMNEvaluationErrorException; import org.kie.kogito.dmn.rest.DMNJSONUtils; @@ -73,10 +76,9 @@ public ResponseEntity dmn(@RequestBody(required = false) $inputType$ variable @GetMapping(produces = MediaType.APPLICATION_XML_VALUE) public String dmn() throws java.io.IOException { - return new String(org.drools.util.IoUtils. - readBytesFromInputStream(this.getClass() - .getResourceAsStream(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.escapeIdentifier("$modelName$") + - ".dmn_nologic"))); + try (InputStream is = this.getClass().getResourceAsStream(CodegenStringUtil.escapeIdentifier("$modelName$") + ".dmn_nologic")) { + return new String(org.drools.util.IoUtils.readBytesFromInputStream(Objects.requireNonNull(is))); + } } private Entry buildFailedEvaluationResponse(KogitoDMNResult result){