Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Refactor the code to remove this label and the need for it.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      LabelsShouldNotBeUsedCheck
    • Targeted languages:
      Flex, PHP, Swift
    • Covered Languages:
      Java, JavaScript
    • Irrelevant for Languages:
      C#, C, C++, Objective-C, Python
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      30min
    • Analysis Scope:
      Main Sources, Test Sources
    • Implementation details:
    • ESLint:
      no-labels

      Description

      Labels are not commonly used in Java, and many developers do not understand how they work. Moreover, their usage makes the control flow harder to follow, which reduces the code's readability.

      Noncompliant Code Example

      int matrix[][] = {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9}
      };
      
      outer: for (int row = 0; row < matrix.length; row++) {   // Non-Compliant
        for (int col = 0; col < matrix[row].length; col++) {
          if (col == row) {
            continue outer;
          }
          System.out.println(matrix[row][col]);                // Prints the elements under the diagonal, i.e. 4, 7 and 8
        }
      }
      

      Compliant Solution

      for (int row = 1; row < matrix.length; row++) {          // Compliant
        for (int col = 0; col < row; col++) {
          System.out.println(matrix[row][col]);                // Also prints 4, 7 and 8
        }
      }
      

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-3773 Language-Specification Active Unassigned
          2.
          Java RSPEC-4772 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fabrice.bellingard Fabrice Bellingard
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: