Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369096

Summary: [common types] StringIndexOutOfBoundsException if JvmDeclaredType has no package
Product: [Modeling] TMF Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: sven.efftinge
Version: 2.3.0Flags: sven.efftinge: juno+
Target Milestone: M5   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Moritz Eysholdt CLA 2012-01-19 10:23:10 EST
calling JdtTypeProvider.findTypeByName with a URI such as java:/Objects/okInteger#okInteger causes 

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1937)
	at org.eclipse.xtext.common.types.access.impl.IndexedJvmTypeAccess.resolveJavaObject(IndexedJvmTypeAccess.java:98)
	at org.eclipse.xtext.common.types.access.impl.IndexedJvmTypeAccess.getIndexedJvmType(IndexedJvmTypeAccess.java:59)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.findTypeByName(JdtTypeProvider.java:85)
Comment 1 Moritz Eysholdt CLA 2012-01-20 05:17:05 EST
The fix should be synchronous to org.eclipse.xtext.common.types.access.impl.AbstractClassMirror... however, AbstractClassMirror seems to assume that the JvmType is always in resource.getContents().get(0). This isn't true for JvmTypes created by a JvmModelInferrer. There, resource.getContents().get(0) is the "original" models and JvmTYpes are at resource.getContents().get(n) with n in [1..n]
Comment 2 Moritz Eysholdt CLA 2012-01-20 09:18:20 EST
The latest code in the repository already has an explicit check for this exception. 
Furthermore, as it turn out, the original cause for this exception was bogus contents of the xtext index so that org.eclipse.xtext.common.types.access.impl.IndexedJvmTypeAccess.resolveJavaObject(JvmType, String) was called this the wrong JvmType.

I'm closing this one as invalid until other evidence shows up.