SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Java

Java static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your JAVA code

  • All rules 733
  • Vulnerability60
  • Bug175
  • Security Hotspot40
  • Code Smell458

  • Quick Fix 65
Filtered: 6 rules found
java24
    Impact
      Clean code attribute
        1. When a defaultFinisher is passed to a Gatherer factory, use the overload that does not take a finisher

           Code Smell
        2. Don't provide an initializer for a stateless stream gatherer

           Code Smell
        3. Gatherer.ofSequential() should be used to build sequential gathers

           Code Smell
        4. "ClassBuilder.withMethodBody" should be preferred to "ClassBuilder.withMethod"

           Code Smell
        5. "transformClass" method should be used instead of "build" when transforming a class

           Code Smell
        6. Class name should be omitted when unchanged by class transform

           Code Smell

        Don't provide an initializer for a stateless stream gatherer

        consistency - conventional
        maintainability
        Code Smell
        • java24

        Why is this an issue?

        Stateless stream gatherers, which process each element of the stream independently, don’t need an initializer function. That’s because the role of the initializer function is to set up the gatherer’s private state object.

        The gatherer interface provides factory methods that create gatherers without taking an initializer as an argument:

        • ofSequential(Gatherer.Integrator<Void,T,R> integrator)
        • ofSequential(Gatherer.Integrator<Void,T,R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher)

        Using these specific factory methods to create stateless gatherers is preferable because it clearly communicates their stateless nature.

        This rule reports the use of ofSequential(Gatherer.Integrator<Void,T,R> integrator, BiConsumer<Void, Gatherer.Downstream<? super R>> finisher) when it returns a stateless gatherer.

        Code examples

        Noncompliant code example

        private static Gatherer inRange(int start, int end) {
            return Gatherer.<Integer, Void, Integer>ofSequential(
              () -> null, // Noncompliant: unnecessary initializer
              (_, element, downstream) -> {
                if (element >= start && element <= end)
                  return downstream.push(element - start);
                return !downstream.isRejecting();
              },
              (_, downstream) -> downstream.push(-1)
            );
        }
        

        Compliant solution

        private static Gatherer inRange(int start, int end) {
            return Gatherer.<Integer, Integer>ofSequential(
              (_, element, downstream) -> {
                if (element >= start && element <= end)
                  return downstream.push(element - start);
                return !downstream.isRejecting();
              },
              (_, downstream) -> downstream.push(-1)
            );
        }
        
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use