forked from Pooja0504/testDemo
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathImproperValidationOfArrayIndex.java
More file actions
37 lines (33 loc) · 959 Bytes
/
Copy pathImproperValidationOfArrayIndex.java
File metadata and controls
37 lines (33 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class ImproperValidationOfArrayIndex{
static int badCase(int data1) throws Throwable{
int array[] = { 0, 1, 2, 3, 4 };
if (data1 < array.length)
{
System.out.println(array[data1]);
}
return data1;
}
static int badCase1(int data1) throws Throwable{
int array[] = { 0, 1, 2, 3, 4 };
if (data1 < array.length) {
System.out.println(array[data1]);
}
return data1;
}
static int goodCase(int data) throws Throwable{
int array[] = { 0, 1, 2, 3, 4 };
if (data >= 0 && data < array.length)
{
System.out.println(array[data]);
}
else
{
System.out.println("Array index out of bounds");
}
return data;
}
public static void main(String args[]) throws Throwable {
int n = badCase(-1);
int m = goodCase(4);
}
}