Skip to content

Commit

Permalink
Modify rule S6466: Fix code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-haubner-sonarsource committed Sep 26, 2023
1 parent 227e4cb commit a46ced5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rules/S6466/java/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Still, accessing an array with its size as an index is not correct:
[source,java,diff-id=2,diff-type=noncompliant]
----
void nonCompliant(int[] arr) {
System.out.println(arr[arr.length]); # Noncompliant: Indexing starts at 0, hence array.length will always be an invalid index.
System.out.println(arr[arr.length]); // Noncompliant: Indexing starts at 0, hence array.length will always be an invalid index.
}
----

Expand All @@ -71,8 +71,8 @@ Still, accessing an array with its size as an index is not correct:
[source,java,diff-id=2,diff-type=compliant]
----
void compliant(int[] arr) {
# We can make sure arr is non-empty before trying to access its last element.
if (array.length > 0) {
// We can make sure arr is non-empty before trying to access its last element.
if (arr.length > 0) {
System.out.println(arr[arr.length - 1]);
} else {
System.out.println("Empty array!");
Expand Down

0 comments on commit a46ced5

Please sign in to comment.