From df5fa046d7855524566b78158fd094ea1ac8a3a4 Mon Sep 17 00:00:00 2001 From: Nico Koprowski Date: Wed, 15 Jan 2025 12:36:14 +0800 Subject: [PATCH] refactor: implement CodeQL suggestions - resolve possible int multiplication overflows - remove unnecessary toString invocations - replace deprecated CSV builder function --- .../test/testdata/pool/BusinessPartnerNonVerboseValues.kt | 6 +++--- .../bpdm/pool/service/BusinessPartnerSearchService.kt | 4 ++-- .../bpdm/pool/util/CreateSQLScriptToInsertRegions.kt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bpdm-common-test/src/main/kotlin/org/eclipse/tractusx/bpdm/test/testdata/pool/BusinessPartnerNonVerboseValues.kt b/bpdm-common-test/src/main/kotlin/org/eclipse/tractusx/bpdm/test/testdata/pool/BusinessPartnerNonVerboseValues.kt index fa6d13042..e25531225 100644 --- a/bpdm-common-test/src/main/kotlin/org/eclipse/tractusx/bpdm/test/testdata/pool/BusinessPartnerNonVerboseValues.kt +++ b/bpdm-common-test/src/main/kotlin/org/eclipse/tractusx/bpdm/test/testdata/pool/BusinessPartnerNonVerboseValues.kt @@ -183,7 +183,7 @@ object BusinessPartnerNonVerboseValues { country = BusinessPartnerVerboseValues.address1.country, postalCode = BusinessPartnerVerboseValues.address1.postalCode, city = BusinessPartnerVerboseValues.address1.city, - administrativeAreaLevel1 = BusinessPartnerVerboseValues.address1.administrativeAreaLevel1?.toString(), + administrativeAreaLevel1 = BusinessPartnerVerboseValues.address1.administrativeAreaLevel1, administrativeAreaLevel2 = BusinessPartnerVerboseValues.address1.administrativeAreaLevel2, administrativeAreaLevel3 = BusinessPartnerVerboseValues.address1.administrativeAreaLevel3, district = BusinessPartnerVerboseValues.address1.district, @@ -201,7 +201,7 @@ object BusinessPartnerNonVerboseValues { country = BusinessPartnerVerboseValues.address2.country, postalCode = BusinessPartnerVerboseValues.address2.postalCode, city = BusinessPartnerVerboseValues.address2.city, - administrativeAreaLevel1 = BusinessPartnerVerboseValues.address2.administrativeAreaLevel1?.toString(), + administrativeAreaLevel1 = BusinessPartnerVerboseValues.address2.administrativeAreaLevel1, administrativeAreaLevel2 = BusinessPartnerVerboseValues.address2.administrativeAreaLevel2, administrativeAreaLevel3 = BusinessPartnerVerboseValues.address2.administrativeAreaLevel3, district = BusinessPartnerVerboseValues.address2.district, @@ -219,7 +219,7 @@ object BusinessPartnerNonVerboseValues { country = BusinessPartnerVerboseValues.address3.country, postalCode = BusinessPartnerVerboseValues.address3.postalCode, city = BusinessPartnerVerboseValues.address3.city, - administrativeAreaLevel1 = BusinessPartnerVerboseValues.address3.administrativeAreaLevel1?.toString(), + administrativeAreaLevel1 = BusinessPartnerVerboseValues.address3.administrativeAreaLevel1, administrativeAreaLevel2 = BusinessPartnerVerboseValues.address3.administrativeAreaLevel2, administrativeAreaLevel3 = BusinessPartnerVerboseValues.address3.administrativeAreaLevel3, district = BusinessPartnerVerboseValues.address3.district, diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerSearchService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerSearchService.kt index 06a5743a5..f91717bb8 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerSearchService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerSearchService.kt @@ -106,7 +106,7 @@ class BusinessPartnerSearchService( totalPages = legalEntityPage.totalPages, page = paginationRequest.page, content = legalEntityPage.content.mapIndexed { index, legalEntity -> - val score = legalEntityPage.totalElements - paginationRequest.page * paginationRequest.size - index + val score = legalEntityPage.totalElements - paginationRequest.page.toLong() * paginationRequest.size.toLong() - index Pair(score.toFloat(), legalEntity) }, contentSize = legalEntityPage.content.size @@ -163,7 +163,7 @@ class BusinessPartnerSearchService( totalPages = addressPage.totalPages, page = paginationRequest.page, content = addressPage.content.mapIndexed { index, address -> - val score = addressPage.totalElements - paginationRequest.page * paginationRequest.size - index + val score = addressPage.totalElements - paginationRequest.page.toLong() * paginationRequest.size.toLong() - index Pair(score.toFloat(), address) }, contentSize = addressPage.content.size diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/CreateSQLScriptToInsertRegions.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/CreateSQLScriptToInsertRegions.kt index 5c7af932b..56b053b50 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/CreateSQLScriptToInsertRegions.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/util/CreateSQLScriptToInsertRegions.kt @@ -32,7 +32,7 @@ class CreateSQLScriptToInsertRegions { fun readCsv(inputStream: InputStream): List = CSVFormat.Builder.create(CSVFormat.DEFAULT).apply { setIgnoreSurroundingSpaces(true) - }.build().parse(inputStream.reader()) + }.get().parse(inputStream.reader()) .drop(1) // Dropping the header .map { RegionDb(