• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ArrayIndexOutOfBoundsException - null

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Biju B Nair
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic