rspec/rules/S1186/java/rule.adoc
Rudy Regazzoni 1763d7fe2b
Modify S1186: Migrate to LayC - empty methods (#3285)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-10-18 18:21:32 +02:00

76 lines
1.4 KiB
Plaintext

== Why is this an issue?
:operationName: method
include::../description.adoc[]
=== Exceptions
This does not raise an issue in the following cases:
* Non-public default (no-argument) constructors
* Public default (no-argument) constructors when there are other constructors in the class
* Empty methods in abstract classes
* Methods annotated with `@org.aspectj.lang.annotation.Pointcut()`
[source,java]
----
public abstract class Animal {
void speak() { // default implementation ignored
}
}
----
== How to fix it
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
public void shouldNotBeEmpty() { // Noncompliant - method is empty
}
public void notImplemented() { // Noncompliant - method is empty
}
@Override
public void emptyOnPurpose() { // Noncompliant - method is empty
}
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
public void doSomething() {
doSomething();
}
public void notImplemented() {
throw new UnsupportedOperationException("notImplemented() cannot be performed because ...");
}
@Override
public void emptyOnPurpose() {
// comment explaining why the method is empty
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]