Skip to content

JAVA-7379 Split define method into smaller methods to comply with line limit - #6557

Merged
leonardo-pilastri-sonarsource merged 1 commit into
masterfrom
remediate-master-20261123-080326-cc00cd69
Nov 24, 2026
Merged

leonardo-pilastri-sonarsource merged 1 commit into
masterfrom
remediate-master-20261123-080326-cc00cd69

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? Single MAJOR severity issue with straightforward resolution through method extraction. The refactoring improves code maintainability and complies with SonarQube standards without altering functional behavior.

The define(Context) method in JavaPlugin exceeded the 100-line limit with 101 lines. This change refactors it into two smaller methods: addProductSpecificExtensions(Context, List) handles the SonarLint branching logic, and coreExtensions() manages the large extensions list, allowing define to focus on composition and fall below the threshold.

View Project in SonarCloud


Fixed Issues

java:S138 - This method has 101 lines, which is greater than the 100 lines authorized. Split it into smaller methods. • MAJOR • View issue

Location: java:sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java:50

Why is this an issue?

A method that grows too large tends to aggregate too many responsibilities. Such method inevitably become harder to understand and therefore harder to maintain.

What changed

Split the 101-line define(Context) method into smaller ones. The SonarLint vs. non-SonarLint branching now lives in addProductSpecificExtensions(Context, List), and the large Arrays.asList block of core extensions now lives in coreExtensions(). define just puts the list together, so it is now under the 100-line limit and does the same thing as before.

diff --git a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java
index 9cc7c81..4306cfa 100644
--- a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java
+++ b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java
@@ -45,11 +45,23 @@ import org.sonar.plugins.surefire.SurefireExtensions;
 
 public class JavaPlugin implements Plugin {
 
-  @SuppressWarnings("unchecked")
   @Override
   public void define(Context context) {
     List<Object> list = new ArrayList<>();
 
+    addProductSpecificExtensions(context, list);
+    if (supportJspTranspilation(context)) {
+      list.add(Jasper.class);
+    }
+    list.addAll(ClasspathProperties.getProperties());
+    list.addAll(coreExtensions());
+
+    list.add(AnalysisWarningsWrapper.class);
+    list.add(DefaultModuleMetadata.class);
+    context.addExtensions(Collections.unmodifiableList(list));
+  }
+
+  private static void addProductSpecificExtensions(Context context, List<Object> list) {
     if (context.getRuntime().getProduct() == SonarProduct.SONARLINT) {
       list.add(NoOpTelemetry.class);
       // Some custom rules (i.e. DBD) depend on the presence of SonarLintCache when executing in a SonarLint context.

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


SonarQube Cloud SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AaIGpn4b5os8fajUEO3l for java:S138 rule

Generated by SonarQube Agent (task: f04512f6-6353-4079-af5a-11eefdcf4d23)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Split define method into smaller methods to comply with line limit JAVA-7379 Split define method into smaller methods to comply with line limit Nov 23, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

JAVA-7379

@sonarqube-next

Copy link
Copy Markdown
Contributor

@leonardo-pilastri-sonarsource
leonardo-pilastri-sonarsource merged commit 89ac8b5 into master Nov 24, 2026
19 checks passed
@leonardo-pilastri-sonarsource
leonardo-pilastri-sonarsource deleted the remediate-master-20261123-080326-cc00cd69 branch November 24, 2026 10:12
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.

2 participants