Methods should not be empty

Description

There are several reasons for a method not to have a method body:

  • It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.

  • It is not yet, or never will be, supported. In this case an exception should be thrown.

  • The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.

Message

Add a nested comment explaining why this method is empty, throw an [UnsupportedOperationException|NotSupportedException| IllegalOperationError] or complete the implementation.

Highlighting

None

List of parameters

None
0% Done
Loading...

Activity

Dinesh BolkensteynAugust 26, 2013 at 12:33 PM

As discussed, this rule should no longer apply to abstract classes to allow default visitor implementations for example

Freddy MalletAugust 7, 2013 at 3:12 PM

Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Default Severity

Critical

Default Quality Profiles

Sonar way

Targeted languages

ABAP
PL/I
PL/SQL
RPG
TypeScript

Covered Languages

C#
C
C++
Flex
Go
Java
JavaScript
Kotlin
Objective-C
PHP
Python
Ruby
Scala
Swift
VB.Net
VB6

Irrelevant for Languages

Cobol
HTML
T-SQL
XML

Remediation Function

Constant/Issue

Constant Cost

Analysis Level

Semantic Analysis

Analysis Scope

Main Sources
Test Sources

Common Rule

Yes

Sentry

Created August 7, 2013 at 3:10 PM
Updated July 20, 2021 at 9:59 AM