onaled777
asked on
Potential for IndexOutOfBoundException
I am currently looking into the potential for an IndexOutOfBoundException. I am examing the code below because it reoccurs pretty frequently.
Does code like this have the potential to throw an IndexOutOfBoundsException? My thought is yes because the Arrays are not synchronized. I would prefer some verification.
byte[] arr = new byte[2048];
int length = 0;
while ((length = pdfInputStream.read(arr)) > 0) {
response.getOutputStream().write(arr, 0, length); //
}
Does code like this have the potential to throw an IndexOutOfBoundsException?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.(API docs for OutputStream.write)
There is no connection between synchronization and such an exception. The way the code is currently written can not cause the violations mentioned above
ASKER