Bug 122458 - java.lang.StringIndexOutOfBoundsException when compiling (build no.: 20051220093604)
Summary: java.lang.StringIndexOutOfBoundsException when compiling (build no.: 20051220...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-02 12:16 EST by Luca Zenti CLA
Modified: 2006-01-11 03:57 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Zenti CLA 2006-01-02 12:16:49 EST
This exception occurs using the ajdt eclipse plugin when compiling a project the first time I add the ajdt nature. There are no aspects defined in the project.
I suppose the exception occurs when compiling a class (sorry I can't post the entire source code) with this signature: 

public class FixedWidthParser<T> extends TabularDataParser<T>

The only noticeable things about this class are the presence of an inherited type parameter (and redefined with same name) some custom annotations on methods and a varags on a method parameter, but all of this things are present on other classes in the same project that AspectJ apprently compiles well (I'm not sure about the fact it compiles them).

Hope I helped you with this clues, here's the complete stacktrace.

java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(Unknown Source)
at org.aspectj.weaver.TypeFactory.createTypeFromSignature(TypeFactory.java:86)
at org.aspectj.weaver.TypeFactory.createTypeFromSignature(TypeFactory.java:116)
at org.aspectj.weaver.UnresolvedType.forSignature(UnresolvedType.java:430)
at org.aspectj.weaver.UnresolvedType.makeArray(UnresolvedType.java:286)
at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.fromBinding(EclipseFactory.java:214)
at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.makeResolvedMember(EclipseFactory.java:516)
at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.makeResolvedMember(EclipseFactory.java:494)
at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.makeResolvedMember(EclipseFactory.java:451)
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.genBytecodeInfo(AsmHierarchyBuilder.java:525)
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.visit(AsmHierarchyBuilder.java:400)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:185)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1195)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:339)
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.internalBuild(AsmHierarchyBuilder.java:142)
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.buildStructureForCompilationUnit(AsmHierarchyBuilder.java:82)
at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.finishedCompilationUnit(EclipseFactory.java:926)
at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterProcessing(AjCompilerAdapter.java:195)
at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$4$6b855184(CompilerAdapter.aj:89)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:528)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:811)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:230)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:156)
at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:122)
at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)

StringIndexOutOfBoundsException thrown: String index out of range: -2
Comment 1 Luca Zenti CLA 2006-01-03 03:56:15 EST
I tried to debug the aspectj weaver code and I found that the signature generating the error is:

Pcom/lynxit/parsers/fixedwidth/FixedWidthParser$Column;

It seems that the lack of '<' character is the problem.
Investigating a little more I discovered that a inner class (even static) of a generic class inherits the type parameters, I don't know if this is in the Java language specs or an eclipse bug but this is surely the cause of the bug I submitted since extracting the inner class to a new type file I'm able to compile the project.

Hope this helps.
Many thanks in advance.
Comment 2 Andrew Clement CLA 2006-01-09 07:24:43 EST
Can I ask the ID of the AJDT build that is the problem?  (Its somewhere in the eclipse about menus), something like 1.3.0.XXXXX.

I fixed a problem similar to this near to completion of 1.5.0.  The problem was that a generic signature was being put out for a type that included a 'P' prefixed type signature.  'P' signatures should never be included in the output bytecode, they are our AJ internal representation for a parameterized type, enabling us to quickly determine if something is parameterized without digging round for the '<'.
Comment 3 Luca Zenti CLA 2006-01-09 07:40:42 EST
The ajdt build number is:

1.3.0.20051220093604
Comment 4 Andrew Clement CLA 2006-01-09 10:51:52 EST
Ok, thats 1.5.0 final - so there is something lurking here. but I just can't seem to tease it out and recreate it.  My current attempts look something like:

===
import java.util.*;

class A<T> { }

class B<T> extends A<T> {
  static class C { T t;}
  class D extends C {}
  List<C>  lcs;
  C[] csArray;
}
===

but that works fine.

Were you able to determine where the P signature originated from?  Was it a signature attribute on some other type or declaration?  Where/How is the Column member type used?  

If you could send me the "javap -verbose -private" output for the problem class that would help ... are you able to send it me privately if you can't append it here?
Comment 5 Luca Zenti CLA 2006-01-09 11:52:32 EST
I eventually succeded in producing a test case that can really isolate the problem:

public class TestCase<T, V>
{
    public void setInnerClasses(InnerClass[] classes){};
    
    public static class InnerClass {}
}

Compiling this class alone (using ajdt) I get the error.
Comment 6 Andrew Clement CLA 2006-01-09 11:59:59 EST
aha... it was being used as a parameter, I see.  Thanks for taking the time to create a smaller failing case.  I can now recreate it on the command line with:

ajc -1.5 Testcase.java -emacssym

(-emaccsym is required to ensure that from the command line we drive the structure model building code that AJDT drives - and thats where it is failing)

I'll get to work on a fix.
Comment 7 Luca Zenti CLA 2006-01-09 12:27:01 EST
I'm glad I helped you guys.
My little contribute to your great job!
Comment 8 Andrew Clement CLA 2006-01-10 05:21:56 EST
testcases and fix checked in.
Comment 9 Andrew Clement CLA 2006-01-11 03:57:51 EST
fix is in latest AJ - will be in AJDT in a few days.