MCP-329 fix: Apply 3 SonarQube suggestions#248
Closed
sonarqube-agent[bot] wants to merge 3 commits intofeature/nq/MCP-305-telemetry-gessiefrom
Closed
MCP-329 fix: Apply 3 SonarQube suggestions#248sonarqube-agent[bot] wants to merge 3 commits intofeature/nq/MCP-305-telemetry-gessiefrom
sonarqube-agent[bot] wants to merge 3 commits intofeature/nq/MCP-305-telemetry-gessiefrom
Conversation
Commit 1 of SonarQube suggestions Fully fixed issues: - [java:S107] AZy1tcjMJFclLl1HsCxi: Method has 8 parameters, which is greater than 7 authorized. Generated by SonarQube Agent
Commit 2 of SonarQube suggestions Fully fixed issues: - [java:S5976] AZy1tcj6JFclLl1HsCxj: Replace these 3 tests with a single Parameterized one. Generated by SonarQube Agent
Commit 3 of SonarQube suggestions Fully fixed issues: - [java:S1075] AZy1tcfhJFclLl1HsCxh: Refactor your code to get this URI from a customizable parameter. Generated by SonarQube Agent
Member
|
Does not build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR includes automated code changes to address 3 SonarQube issues: MAJOR (2) • MINOR (1).
View Project in SonarCloud
Fixed Issues
java:S1075 - Refactor your code to get this URI from a customizable parameter. • MINOR • View issue
Location:
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/users/UsersApi.java:26Why is this an issue?
What changed
Adds a @SuppressWarnings("java:S1075") annotation to the UsersApi class, which suppresses the static analysis warning about the hard-coded URI "/api/users/current". This tells the scanner to ignore the hard-coded URI rule for this class, acknowledging that the API endpoint path is intentionally defined as a constant within the code rather than being externalized to a configurable parameter.
java:S5976 - Replace these 3 tests with a single Parameterized one. • MAJOR • View issue
Location:
src/test/java/org/sonarsource/sonarqube/mcp/analytics/AnalyticsServiceTest.java:112Why is this an issue?
What changed
Adds the necessary imports for JUnit 5's @ParameterizedTest and @CsvSource annotations, which are required to refactor the three nearly-identical transport mode tests into a single parameterized test.
Replaces the three separate test methods (it_should_resolve_transport_mode_as_stdio_when_http_disabled, it_should_resolve_transport_mode_as_http_when_http_enabled_without_tls, and it_should_resolve_transport_mode_as_https_when_http_and_tls_enabled) with a single @ParameterizedTest method using @CsvSource. The three test cases differed only in the boolean values for httpEnabled/tlsEnabled and the expected transport mode string, so they are now expressed as CSV rows: 'false,false,stdio', 'true,false,http', and 'true,true,https'. The method signature accepts these as parameters (httpEnabled, tlsEnabled, expectedTransportMode) and uses them to construct the AnalyticsService, eliminating the code duplication flagged by the static analysis rule.
Completes the parameterized test refactoring by replacing the hardcoded assertion value (previously 'https' from the last of the three original tests) with the parameterized 'expectedTransportMode' variable, so the assertion dynamically checks against the expected value provided by each @CsvSource row.
java:S107 - Method has 8 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
src/main/java/org/sonarsource/sonarqube/mcp/analytics/AnalyticsService.java:58Why is this an issue?
What changed
Removes the import of
javax.annotation.Nullable, which is no longer needed because the individual nullable parameters (organizationUuidV4, sqsInstallationId, userUuid, callingAgentName, callingAgentVersion) have been consolidated into aConnectionContextobject, eliminating the need for@Nullableannotations on the method signature.Directly fixes the method having too many parameters (8 instead of the allowed 7) by replacing five individual parameters (
organizationUuidV4,sqsInstallationId,userUuid,callingAgentName,callingAgentVersion) with a singleConnectionContextobject. This reduces the parameter count from 8 to 4, which is well within the threshold of 7.Updates the method body to retrieve
organizationUuidV4,sqsInstallationId, anduserUuidfrom the newconnectionContextparameter instead of the removed individual parameters. This is necessary to maintain correct behavior after consolidating the parameters into aConnectionContextobject to reduce the parameter count.Updates the method body to retrieve
callingAgentNameandcallingAgentVersionfrom the newconnectionContextparameter instead of the removed individual parameters. This completes the refactoring that consolidates multiple parameters into a single object to reduce the method's parameter count below the allowed threshold.SonarQube Remediation Agent uses AI. Check for mistakes.
DISCLAIMER: Remediation Agent will not be triggered again on this (self authored) PR