wood burning stoves 2.0*
The moose likes Java in General and the fly likes java.lang.ArrayIndexOutOfBoundsException - null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.ArrayIndexOutOfBoundsException - null" Watch "java.lang.ArrayIndexOutOfBoundsException - null" New topic
Author

java.lang.ArrayIndexOutOfBoundsException - null

man pat
Greenhorn

Joined: Aug 05, 2011
Posts: 12
Give simple example which throws java.lang.ArrayIndexOutOfBoundsException null.
Note null is the thing I am looking for and not any integer index.

FYI: I know if String names[] = new String[3]; System.out.println("Fifth Name: " + names[4] + ":"); // I know it will throw java.lang.ArrayIndexOutOfBoundsException: 4 - I am fine with this)

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
Most of the places where you get out of bounds exceptions supply the index as a number, as you will see from its API documentation. You would have to pass such a String to its constructor.
man pat
Greenhorn

Joined: Aug 05, 2011
Posts: 12
Thanks Campbell.

* I am trying to find cause for this exception in my application(written by somebody). I dont see - throw new ArrayIndexOutOfBoundsException("null"); in the code.
* I am trying to reproduce this exception. Can you or somebody show other scenarios?


Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122



I do get an exception like what you show:
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.<init>(Unknown Source)
at com.sample.OOBNull.main(OOBNull.java:7)

so I am thinking the code referencing the array may be using an Integer or other object which can get cast to an int, but for which there is a null value in it?

<<oooops>> I paid attention to the "null" and not the number format exception. Disregard the example, but I figured I'd leave it here in case it triggers other thoughts.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
You won’t get java.lang.ArrayIndexOutOfBoundsException - null out of that sort of code.

Unless somebody has got something like this
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, if it were my problem, I would have started by looking at the stack trace. Challenging other people to generate similar scenarios based on no information just doesn't seem like a productive approach, to me.
man pat
Greenhorn

Joined: Aug 05, 2011
Posts: 12
Thanks All.

* If I was having more info(No stack trace) then I would have shared that. My Manager(no wonder it is challenging:-) had sent this bug with the info from the log file.

2011-09-30 09:49:14,704 [com.xyz.abc.ddd.exceptions.BBBBB] Thread-228 184 FATAL - UNKNOWN EXCEPTION ENCOUNTERED.
2011-09-30 09:49:14,706 [com.xyz.abc.ddd.exceptions.BBBBB] Thread-228 609 FATAL - [ java.lang.ArrayIndexOutOfBoundsException ] nulljava.lang.ArrayIndexOutOfBoundsException

2011-09-30 09:49:14,707 [com.xyz.abc.ddd.exceptions.BBBBB Thread-228 610 FATAL - DDD LOADER TERMINATED............

I felt challenging that's why I have asked this question. I know when you are looking for help it makes no sense if other person gets the impression that this person doesnot deserve help.
Biju B Nair
Greenhorn

Joined: Jan 09, 2012
Posts: 1
This is not a normal way how the ArrayIndexOutOfBoundsException exception occurs. Most of the time it displays the index as its message.
But this exception also has an default constructor (new ArrayIndexOutOfBoundsException()). I think your code may be throwing such exception from somewhere in the code, where exception.getMessage will be null.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

man pat wrote:Thanks All.

* If I was having more info(No stack trace) then I would have shared that. My Manager(no wonder it is challenging:-) had sent this bug with the info from the log file.

2011-09-30 09:49:14,704 [com.xyz.abc.ddd.exceptions.BBBBB] Thread-228 184 FATAL - UNKNOWN EXCEPTION ENCOUNTERED.
2011-09-30 09:49:14,706 [com.xyz.abc.ddd.exceptions.BBBBB] Thread-228 609 FATAL - [ java.lang.ArrayIndexOutOfBoundsException ] nulljava.lang.ArrayIndexOutOfBoundsException


That's some pretty awful logging. If that's all the information that's available, then all anybody can tell you is that you're trying to access an element outside the range of 0..arr.length - 1, that is, either a negative index or one that's greater than or equal to the number of elements in the array in question. But you already knew that, right?
man pat
Greenhorn

Joined: Aug 05, 2011
Posts: 12
Thanks Biju B. Biju had provided following scenario:


Jeff V: Yes, I am aware about that.

Thanks You All. I will wait next time when it occurs. Hopefully that it will provide more info. I will stop watching this thread till then.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
Welcome to the Ranch Biju B Nair
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ArrayIndexOutOfBoundsException - null
 
Similar Threads
java.lang.ArrayIndexOutOfBoundsException: 1
DTO / ejb ql
initalizing arrays
Marcus Green Mock
Read and search text in HTML - ArrIndOutOfBoundsException: 88