rspec/rules/S6780/java/rule.adoc

19 lines
660 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
Assertions in Java are used to test assumptions that should hold true at a certain point in the program. An assertion with a condition that is always false will fail, which can lead to unexpected program termination. Moreover, an assertion that is always false often indicates a logic error or misunderstanding in the code, which could lead to further issues.
=== Noncompliant code example
[source,java]
----
void caller() {
// Noncompliant: triggers an AssertionError because the array length is 2
printFifth(new int[2]);
}
void printFifth(int[] a) {
assert a.length == 5;
System.out.println(a[4]);
}
----