SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-128

Rule S00108: Nested blocks of code should not be left empty

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: Squid
    • Labels:
      None
    • Number of attachments :
      0

      Description

      http://jira.sonarsource.com/browse/RSPEC-108

      And depreciate Checkstyle rule com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck

        Issue Links

          Activity

          Hide
          Evgeny Mandrikov added a comment -

          Integration tests were updated.

          Show
          Evgeny Mandrikov added a comment - Integration tests were updated.
          Hide
          Fabrice Bellingard added a comment -

          Tested

          Show
          Fabrice Bellingard added a comment - Tested
          Hide
          Evgeny Mandrikov added a comment - - edited

          Following PMD rules also should be marked as deprecated, as they covered by this rule:

          • EmptyCatchBlock
          • EmptyFinallyBlock
          • EmptyIfStmt
          • EmptyInitializer
          • EmptyStaticInitializer
          • EmptySwitchStatements
          • EmptySynchronizedBlock
          • EmptyTryBlock
          • EmptyWhileStmt
          Show
          Evgeny Mandrikov added a comment - - edited Following PMD rules also should be marked as deprecated, as they covered by this rule: EmptyCatchBlock EmptyFinallyBlock EmptyIfStmt EmptyInitializer EmptyStaticInitializer EmptySwitchStatements EmptySynchronizedBlock EmptyTryBlock EmptyWhileStmt
          Hide
          Fabrice Bellingard added a comment -

          Indeed, checked!

          Show
          Fabrice Bellingard added a comment - Indeed, checked!
          Hide
          Evgeny Mandrikov added a comment -

          Integration tests were updated.

          Show
          Evgeny Mandrikov added a comment - Integration tests were updated.
          Hide
          Freddy Mallet added a comment -

          I'm reopening this rule to not log a violation when an empty block contain at least one comment whatever is the type and the content of this comment.

          Example :

          if ("+".equals(op)) {
            // nothing to do           -> Compliant as empty block with a comment
          } else if ("-".equals(op)) {
            result = -result;
          } else if ("~".equals(op) || "compl".equals(op)) {
            result = ~result;
          } else {
            throw new UnsupportedOperationException();
          }
          
          Show
          Freddy Mallet added a comment - I'm reopening this rule to not log a violation when an empty block contain at least one comment whatever is the type and the content of this comment. Example : if ( "+" .equals(op)) { // nothing to do -> Compliant as empty block with a comment } else if ( "-" .equals(op)) { result = -result; } else if ( "~" .equals(op) || "compl" .equals(op)) { result = ~result; } else { throw new UnsupportedOperationException(); }
          Hide
          Freddy Mallet added a comment - - edited

          Here is the updated documentation :

          Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed. When a block contains only a comment, this block is not considered to be empty.

          The following code snippet illustrates this rule:

          void doSomething() {
            int myVar= 0;
            for (int i = 0; i< 4; i++)  // Non-Compliant
            {                           
            }
            for (int i = 0; i< 4; i++); // Compliant as there is no block
          
            if (myVar == 4)             // Compliant as the block contains at least a comment
            {  
              //Nothing to do
            } else {
              doSomething();
            }
          
            try                         // Non-Compliant
            {
            }
            catch (Exception e)         // Non-Compliant
            {                           
            }
          }
          
          Show
          Freddy Mallet added a comment - - edited Here is the updated documentation : Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed. When a block contains only a comment, this block is not considered to be empty. The following code snippet illustrates this rule: void doSomething() { int myVar= 0; for ( int i = 0; i< 4; i++) // Non-Compliant { } for ( int i = 0; i< 4; i++); // Compliant as there is no block if (myVar == 4) // Compliant as the block contains at least a comment { //Nothing to do } else { doSomething(); } try // Non-Compliant { } catch (Exception e) // Non-Compliant { } }
          Hide
          Evgeny Mandrikov added a comment -

          Done.

          Show
          Evgeny Mandrikov added a comment - Done.
          Hide
          Freddy Mallet added a comment -

          Manually tested !

          Show
          Freddy Mallet added a comment - Manually tested !

            People

            • Assignee:
              Evgeny Mandrikov
              Reporter:
              Freddy Mallet
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: