Skip to content

Commit

Permalink
Modify rule S6466: Fix headings
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-haubner-sonarsource committed Sep 26, 2023
1 parent a46ced5 commit a904e9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 8 additions & 9 deletions rules/S6466/java/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ When trying to access an array outside of this range, an

include::../impact.adoc[]

== How can I fix it?
== How to fix it

The following are examples of code containing out-of-bounds accesses to
arrays, resulting in `ArrayIndexOutOfBounds` exceptions.
Expand All @@ -33,7 +33,7 @@ index `3`.

[source,java,diff-id=1,diff-type=noncompliant]
----
void nonCompliant() {
void fun() {
int[] arr = {1, 2, 3};
int x = arr[3]; // Noncompliant: Valid indices are 0, 1 and 2
Expand All @@ -45,7 +45,7 @@ index `3`.

[source,java,diff-id=1,diff-type=compliant]
----
void compliant() {
void fun() {
int[] arr = {1, 2, 3};
int x = arr[0];
Expand All @@ -61,7 +61,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) {
void fun(int[] arr) {
System.out.println(arr[arr.length]); // Noncompliant: Indexing starts at 0, hence array.length will always be an invalid index.
}
----
Expand All @@ -70,7 +70,7 @@ 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) {
void fun(int[] arr) {
// 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]);
Expand Down Expand Up @@ -113,18 +113,17 @@ The API provides methods like `map()` or `filter()` that allow you to transform,
filter and perform many different operations on the elements of an array without
using indices.

== More Info

=== Resources
== Resources

==== Documentation
=== Documentation

* https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ArrayIndexOutOfBoundsException.html[ArrayIndexOutOfBoundsException]
* https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.4[Array Access Specification]
* https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#stream-T:A-[`Arrays.stream()`]
* https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html[Stream API]

==== Articles & blog posts
=== Articles & blog posts

* A Reference Guide - https://www.baeldung.com/java-arrays-guide[Arrays in Java]

Expand Down
8 changes: 3 additions & 5 deletions rules/S6466/python/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Thus, the result must be non-negative and fit into the aforementioned range.

include::../impact.adoc[]

== How can I fix it?
== How to fix it

The following are examples of code containing out-of-bounds accesses to
sequences, resulting in `IndexError`s.
Expand Down Expand Up @@ -130,11 +130,9 @@ for i, elem in enumerate(ls):
foo(i, elem)
----

== More Info
== Resources

=== Resources

==== Documentation
=== Documentation

* https://docs.python.org/3/reference/expressions.html#subscriptions[Subscriptions]
* https://docs.python.org/3/library/exceptions.html#IndexError[`IndexError`]
Expand Down

0 comments on commit a904e9e

Please sign in to comment.