• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayIndexOutOfBoundsException - null

 
man pat
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won’t get java.lang.ArrayIndexOutOfBoundsException - null out of that sort of code.

Unless somebody has got something like this
 
Paul Clapham
Sheriff
Posts: 21558
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Biju B Nair
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic