Skip to content

Commit a2e49f8

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] sonarcloud: Fix this access on a collection that may trigger an 'ArrayIndexOutOfBoundsException'.
Accessing an array element should not trigger an ArrayIndexOutOfBoundsException javabugs:S6466
1 parent 6559d02 commit a2e49f8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

algorithm-exercises-java/src/main/java/ae/projecteuler/Problem0015.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ private Problem0015() {}
1616
*/
1717
public static Long problem0015(Integer gridSide) {
1818

19-
Long[][] grid = new Long[gridSide + 1][gridSide + 1];
19+
int limit = gridSide + 1;
20+
Long[][] grid = new Long[limit][limit];
2021

2122
// initialization
2223
for (int i = 0; i <= gridSide; i++) {
@@ -26,8 +27,8 @@ public static Long problem0015(Integer gridSide) {
2627
}
2728

2829
// vertex computing
29-
for (int i = 1; i <= gridSide; i++) {
30-
for (int j = 1; j <= gridSide; j++) {
30+
for (int i = 1; i < limit; i++) {
31+
for (int j = 1; j < limit; j++) {
3132
long upperParent = grid[i - 1][j];
3233
long leftParent = grid[i][j - 1];
3334

0 commit comments

Comments
 (0)