Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 461250 - ArrayIndexOutOfBoundsException in SourceTypeBinding.fields
Summary: ArrayIndexOutOfBoundsException in SourceTypeBinding.fields
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.5 M6   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 424900 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-03-02 17:34 EST by Carmi Grushko CLA
Modified: 2015-05-02 18:38 EDT (History)
3 users (show)

See Also:


Attachments
Repro code. Just run and you'll get the exception. (1.31 KB, text/plain)
2015-03-02 17:34 EST, Carmi Grushko CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carmi Grushko CLA 2015-03-02 17:34:36 EST
Created attachment 251227 [details]
Repro code. Just run and you'll get the exception.

Repro case attached.

Stack trace:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:720)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:698)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:420)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1193)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:685)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1181)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:807)
	at com.company.HelloWorld.parseAndResolveSource(HelloWorld.java:29)
	at com.company.HelloWorld.main(HelloWorld.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

(yes, I created the repro in IntelliJ :) )
Comment 1 Stephan Herrmann CLA 2015-03-02 18:07:14 EST
Thanks for the convenient repro!

The problem is caused by very unhappy re-entrance during resolution of buggy code.
Comment 2 Eclipse Genie CLA 2015-03-02 18:11:08 EST
New Gerrit change created: https://git.eclipse.org/r/43050
Comment 4 Stephan Herrmann CLA 2015-03-02 19:41:42 EST
During a re-entrant call this.fields was shrunk to remove fields in error. The outer call, however, still used the old length as its loop boundary -> AIOOBE.
Fixed by working on a pair of local variables, instead of a field + a local.

As an optimization we could detect the situation and abort the outer fields() computation (because inner has already done all work), but since this would only help for error cases and probably helps only marginally, I don't think it's worth it.

Released for 4.5 M6.
Comment 5 Carmi Grushko CLA 2015-03-02 19:54:40 EST
Wow, I'm seriously surprised it got fixed so fast...  :D
Awesome, thanks so much!!!
Comment 6 Jay Arthanareeswaran CLA 2015-03-18 01:28:39 EDT
Verified for 4.5 M6 with build I20150317-2000
Comment 7 Stephan Herrmann CLA 2015-05-02 18:38:31 EDT
*** Bug 424900 has been marked as a duplicate of this bug. ***