Help for the Java challenged: how can ArrayIndexOutOfBoundsException be thrown here?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help for the Java challenged: how can ArrayIndexOutOfBoundsException be thrown here?

Nathan Ridge
Hi folks,

Java is not my strong suit so I was hoping someone could help me out.

I'm looking at an error report where an ArrayIndexOutOfBoundsException is thrown. Here is the relevant part of the stack trace:

java.lang.ArrayIndexOutOfBoundsException: null
    at java.util.ArrayList.toArray(ArrayList.java:408)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScopeMapper$NamespaceScopeWrapper.getUsingDirectives(CPPScopeMapper.java:168)

The code at the indicated line is:

                        return fUsingDirectives.toArray(new ICPPUsingDirective[fUsingDirectives.size()]);

The previous line ensures that fUsingDirectives is not null.

I don't see how an ArrayIndexOutOfBoundsException can be thrown in this case. (But I also can't see the source of the ArrayList.toArray() method to see what exactly it's trying to do.)

Any ideas as to how this exception can arise in this case?

Thanks,
Nate

[1] https://dev.eclipse.org/recommenders/committers/aeri/v2/#!/incidents/58a59438e4b05548a19b679b
_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help for the Java challenged: how can ArrayIndexOutOfBoundsException be thrown here?

Christian Walther-2
Nathan Ridge wrote:
> return fUsingDirectives.toArray(new ICPPUsingDirective[fUsingDirectives.size()]);
>
> The previous line ensures that fUsingDirectives is not null.
>
> I don't see how an ArrayIndexOutOfBoundsException can be thrown in this case. (But I also can't see the source of the ArrayList.toArray() method to see what exactly it's trying to do.)

I imagine this could happen if some other thread is concurrently adding items to fUsingDirectives.

 -Christian

_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help for the Java challenged: how can ArrayIndexOutOfBoundsException be thrown here?

Jonah Graham
Hi Nate,

I suspect Christian is right about the cause. There are a few
(potential) race conditions in that class. Between the call to size()
and toArray() a new item could be added in addUsingDirective,
additionally, between the call to size and toArray you could have
fUsingDirectives being reinit if two threads are calling
initUsingDirectives at the same time.

As for the source of toArray, you can get it by configuring your JRE
to have the source:
https://dzone.com/articles/attaching-java-source-eclipse However in
this error report the exception is being raised from the native
System.arraycopy code (called by toArray).

Jonah
~~~
Jonah Graham
Kichwa Coders Ltd.
www.kichwacoders.com


On 21 February 2017 at 06:58, Christian Walther <[hidden email]> wrote:

> Nathan Ridge wrote:
>>                       return fUsingDirectives.toArray(new ICPPUsingDirective[fUsingDirectives.size()]);
>>
>> The previous line ensures that fUsingDirectives is not null.
>>
>> I don't see how an ArrayIndexOutOfBoundsException can be thrown in this case. (But I also can't see the source of the ArrayList.toArray() method to see what exactly it's trying to do.)
>
> I imagine this could happen if some other thread is concurrently adding items to fUsingDirectives.
>
>  -Christian
>
> _______________________________________________
> cdt-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev