rspec/rules/S3040/java/rule.adoc

64 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
In certain Android methods, calls to the ``++super++`` version of the method should always come first. Otherwise, you risk leaving the job half-done.
This rule raises an issue when the following ``++Activity++`` methods do not begin with a call to ``++super++``:
* ``++onCreate++``
* ``++onConfigurationChanged++``
* ``++onPostCreate++``
* ``++onPostResume++``
* ``++onRestart++``
* ``++onRestoreInstanceState++``
* ``++onResume++``
* ``++onStart++``
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void onCreate(Bundle bundle) { // Noncompliant; super call missing
doSomething();
}
public void onPostCreate(Bundle bundle) {
doSomethingElse();
super.onPostCreate(bundle); // Noncompliant; should be first statement
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
doSomething();
}
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
doSomethingElse();
}
----
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[]