rspec/rules/S112/java/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

65 lines
1.7 KiB
Plaintext

== Why is this an issue?
Using such generic exceptions as ``++Error++``, ``++RuntimeException++``, ``++Throwable++``, and ``++Exception++`` prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.
=== Noncompliant code example
[source,java]
----
public void foo(String bar) throws Throwable { // Noncompliant
throw new RuntimeException("My Message"); // Noncompliant
}
----
=== Compliant solution
[source,java]
----
public void foo(String bar) {
throw new MyOwnRuntimeException("My Message");
}
----
=== Exceptions
Generic exceptions in the signatures of overriding methods are ignored, because overriding method has to follow signature of the throw declaration in the superclass. The issue will be raised on superclass declaration of the method (or won't be raised at all if superclass is not part of the analysis).
[source,java]
----
@Override
public void myMethod() throws Exception {...}
----
Generic exceptions are also ignored in the signatures of methods that make calls to methods that throw generic exceptions.
[source,java]
----
public void myOtherMethod throws Exception {
doTheThing(); // this method throws Exception
}
----
== Resources
* https://cwe.mitre.org/data/definitions/397[MITRE, CWE-397] - Declaration of Throws for Generic Exception
* https://wiki.sei.cmu.edu/confluence/x/_DdGBQ[CERT, ERR07-J.] - Do not throw RuntimeException, Exception, or Throwable
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[]