Skip to content

fix: resolve 3 SonarQube code quality issues in TransformationService#50

Open
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
remediate-main-20260510-090210-fb18f10c
Open

fix: resolve 3 SonarQube code quality issues in TransformationService#50
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
remediate-main-20260510-090210-fb18f10c

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Fixed three SonarQube violations in TransformationService: replaced generic RuntimeException with specific IllegalStateException, extracted nested try block into separate fetchNextPage() method to improve readability, and removed dead commented code. These improvements enhance code maintainability and follow Java best practices for exception handling and code clarity.

View Project in SonarCloud


Fixed Issues

java:S112 - Replace generic exceptions with specific library exceptions or a custom exception. • MAJORView issue

Location: src/main/java/fr/ans/psc/pscextract/service/TransformationService.java:400

Why is this an issue?

Throwing generic exceptions such as Error, RuntimeException, Throwable, and Exception will have a negative impact on any code trying to catch these exceptions.

What changed

Replaces the generic RuntimeException with the more specific IllegalStateException. This addresses the code smell about throwing generic exceptions, since IllegalStateException is a specific exception that better communicates the nature of the error (the JVM is in an unexpected state where SHA256 digest is not available).

--- a/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
+++ b/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
@@ -400,1 +386,1 @@ public class TransformationService {
-          throw new RuntimeException("No SHA256 digest support in the current java runtime - please fix this."+ex.getMessage(),ex);
+          throw new IllegalStateException("No SHA256 digest support in the current java runtime - please fix this."+ex.getMessage(),ex);
java:S1141 - Extract this nested try block into a separate method. • MAJORView issue

Location: src/main/java/fr/ans/psc/pscextract/service/TransformationService.java:344

Why is this an issue?

Nesting try/catch blocks severely impacts the readability of source code because it makes it too difficult to understand which block will catch which exception.

What changed

Extracts the nested try block into a separate method call fetchNextPage(), which eliminates the nested try/catch structure that severely impacted readability. Instead of having a try/catch nested inside another try block, the inner logic is now delegated to a helper method, and the result is checked via a simple null comparison.

--- a/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
+++ b/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
@@ -344,14 +344,2 @@ public class TransformationService {
-                try {
-                    response = extractionController.getPsApi().getPsByPage(BigDecimal.valueOf(page), size);
-                    log.debug("Page " + page + " of size " + size + " received, writing to file...");
-                } catch (HttpStatusCodeException e) {
-                    log.warn("Out of pages: " + e.getMessage());
-                    if (e.getStatusCode() != HttpStatus.GONE) {
-                        log.info("Extraction failed, exiting without replacing the extract file");
-                        if (tempExtractFile.delete()) {
-                            log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted");
-                        } else {
-                            log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted");
-                        }
-                        return null;
-                    }
+                response = fetchNextPage(extractionController, page, size);
+                if (response == null) {
java:S125 - This block of commented-out lines of code should be removed. • MAJORView issue

Location: src/main/java/fr/ans/psc/pscextract/service/TransformationService.java:78

Why is this an issue?

Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid.

What changed

Removes the commented-out line of code if (s.charAt(1) == '0') return s+','+'MSSante'+','+'1'; which was flagged as a block of commented-out code that should be removed. The line is replaced with just a blank comment, eliminating the dead code that was distracting from the actual executed code.

--- a/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
+++ b/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java
@@ -78,1 +78,1 @@ public class TransformationService {
-                // if (s.charAt(1) == '0') return s+','+"MSSante"+','+'1';
+                //

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZZjJ298STHyJcTACtyF for java:S125 rule
- AZZjJ298STHyJcTACtyA for java:S1141 rule
- AZZjJ298STHyJcTACtyB for java:S112 rule

Generated by SonarQube Agent (task: 56119646-0ae0-4a14-9ba2-d3fc0a996bc1)
@sonarqube-agent
Copy link
Copy Markdown
Author

⚠️ This repository does not have a CODEOWNERS file. The PR has been created but has not been automatically assigned to any reviewer. To ensure PRs are reviewed promptly, consider adding a CODEOWNERS file to your repository.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants