Bug 333066 - StringIndexOutOfBoundsException during compilation
Summary: StringIndexOutOfBoundsException during compilation
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.10   Edit
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-22 05:47 EST by Neale Upstone CLA
Modified: 2014-08-20 15:02 EDT (History)
2 users (show)

See Also:


Attachments
ajcore dump (23.75 KB, text/plain)
2010-12-22 06:21 EST, Neale Upstone CLA
no flags Details
1.6.11.M2 stack dump (26.52 KB, text/plain)
2011-02-25 05:27 EST, Neale Upstone CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Neale Upstone CLA 2010-12-22 05:47:27 EST
The following happens when compiling with 1.6.10.

Referred Spring version is 3.0.3

Severity set as Major, as it breaks this build (although thankfully it's 'only' our enforce-policies nightly).

[ERROR] Internal compiler error
java.lang.RuntimeException: Problem processing attributes in org/springframework/beans/factory/aspectj/AnnotationBeanConfigurerAspect.class
	at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:383)
	at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.java:160)
	at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegate(BcelWorld.java:382)
	at org.aspectj.weaver.bcel.BcelWorld.resolveDelegate(BcelWorld.java:377)
	at org.aspectj.weaver.World.resolveToReferenceType(World.java:452)
	at org.aspectj.weaver.World.resolve(World.java:298)
	at org.aspectj.weaver.World.resolve(World.java:211)
	at org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory.fromEclipse(EclipseFactory.java:148)
	at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.weaveInterTypeDeclarations(AjLookupEnvironment.java:647)
	at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.weaveInterTypeDeclarations(AjLookupEnvironment.java:636)
	at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.createBinaryTypeFrom(AjLookupEnvironment.java:1346)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:599)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:276)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:139)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:178)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.findImport(CompilationUnitScope.java:451)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.findSingleImport(CompilationUnitScope.java:505)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInImports(CompilationUnitScope.java:361)
	at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:430)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:629)
	at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1022)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:268)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:181)
	at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
	at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
	at org.aspectj.tools.ajc.Main.run(Main.java:363)
	at org.aspectj.tools.ajc.Main.runMain(Main.java:240)
	at org.codehaus.mojo.aspectj.AbstractAjcCompiler.execute(AbstractAjcCompiler.java:381)
	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
	at hudson.maven.agent.PluginManagerInterceptor.executeMojo(PluginManagerInterceptor.java:182)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
	at org.apache.maven.lifecycle.LifecycleExecutorInterceptor.execute(LifecycleExecutorInterceptor.java:65)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at hudson.maven.agent.Main.launch(Main.java:165)
	at hudson.maven.MavenBuilder.call(MavenBuilder.java:165)
	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:694)
	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:638)
	at hudson.remoting.UserRequest.perform(UserRequest.java:114)
	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
	at hudson.remoting.Request$2.run(Request.java:270)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:686)
	at org.aspectj.weaver.UnresolvedType.forSignature(UnresolvedType.java:416)
	at org.aspectj.weaver.UnresolvedType.read(UnresolvedType.java:847)
	at org.aspectj.weaver.WeaverStateInfo.read(WeaverStateInfo.java:142)
	at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:105)
	at org.aspectj.weaver.bcel.Utility.readAjAttributes(Utility.java:101)
	at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:379)
Comment 1 Neale Upstone CLA 2010-12-22 06:21:28 EST
Created attachment 185694 [details]
ajcore dump
Comment 2 Andrew Clement CLA 2011-01-20 17:30:01 EST
I don't know why, but I'm having real trouble recreating this problem.  I have 1.6.10, I have spring-aspects-3.0.3.RELEASE.jar.  The index of out bounds exception indicates there is a typename with 0 length in the jar.
Of course, I am making an assumption that it is getting the AnnotationBeanConfigurerAspect from the spring-aspects jar, but it should be.
Comment 3 Andrew Clement CLA 2011-02-04 17:56:46 EST
Although I couldn't recreate this issue, I have uncovered an error with attribute serialization whilst working on another bug, which *could* be related.  This is fixed in the latest dev build:

http://eclipse.org/aspectj/downloads.php

If you have a moment, I'd be really interested in you trying out the failing scenario with that weaver. thanks.  If you don't have time to grab a jar and try it, I'll probably be putting a 1.6.11.M2 out shortly with the change in it.
Comment 4 Neale Upstone CLA 2011-02-05 12:42:30 EST
Thanks Andy.

I'll give the dev build a go next week when I'm back (from skiing :-)
Comment 5 Neale Upstone CLA 2011-02-14 05:40:53 EST
Back, but gonna wait for the milestone as rather pushed for time.
Comment 6 Andrew Clement CLA 2011-02-24 12:36:57 EST
can you attach an updated stack trace with 1.6.11.m2, in case it is subtly different.
Comment 7 Neale Upstone CLA 2011-02-25 05:27:57 EST
Created attachment 189782 [details]
1.6.11.M2 stack dump
Comment 8 Andrew Clement CLA 2013-06-24 11:03:12 EDT
unsetting the target field which is currently set for something already released
Comment 9 Neale Upstone CLA 2013-06-24 11:17:56 EDT
Andy,

As I've not seen this since, I think it would make sense to close as "works for me".  I don't even know what codebase it was that generated that issue now.
Comment 10 Dan Morari CLA 2014-08-19 09:52:02 EDT
I'm not sure this is the same bug, though the stacktrace looks quite similar. 

Using AspectJ 1.8.1, Java 8.

I get the following exception when class having this method 
  public String getString()  {
    Optional<String> dummy = Optional.of("Just a dummy optional");
    return dummy.orElseThrow(() ->    {
      return new RuntimeException();
    });
  }
is woven: 
[AppClassLoader@58644d46] abort trouble in: 
public class com.foo.Bar extends java.lang.Object:

// Bytecode of the class

Aug 19, 2014 4:28:51 PM org.aspectj.weaver.tools.Jdk14Trace error
SEVERE: com/inthergroup/aspect/retry/config/Parser
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:646)
	at org.aspectj.weaver.UnresolvedType.forSignature(UnresolvedType.java:383)



While this works fine :
  public String getString()  {
    Optional<String> dummy = Optional.of("Just a dummy optional");
    return dummy.orElseThrow(RuntimeException::new);
  }
Comment 11 Andrew Clement CLA 2014-08-19 12:27:03 EDT
Hey Dan,

I'm trying to recreate that without much luck, I wrapped up your snippet with an aspect but I can't make it fail (at AspectJ 1.8.0/1.8.1 or 1.8.2):

=== Code.java ===
import java.util.*;

public class Code {
  public String getString()  {
    Optional<String> dummy = Optional.of("Just a dummy optional");
    return dummy.orElseThrow(() ->    {
      return new RuntimeException();
    });
  }
}

aspect X {
  before(): within(!X) {System.out.println(thisJoinPoint);}
}
===

Can you distill it into a small failing example? I'm not sure what kind of advice or pointcut you are having trouble with.
Comment 12 Dan Morari CLA 2014-08-20 02:50:11 EDT
Hi Andrew,

The preceding example is not a part of an aspect source code : this is a simple class; I don't have any aspect matching this class - theoretically it should remain untouched. 

The only one thing - Code.java class belongs to a package configured to be scanned in the aop.xml. 

<aspectj>
  <weaver options="-showWeaveInfo
-Xset:overWeaving=true">
    <include within="com.package.where.the.class.is..*" />
  </weaver>
  <aspects>
    
  </aspects>

AspectJ produces that error in output during the loadtime weaving, while compilation using aspectj-maven-plugin doesn't have issues. 
After error is printed, it skips this class and moves forward. 

I think it happens when AspectJ attempts to parse bytecode of that class, and guess this logic doesn't depend on aspects defined. 

If I'm mistaken and what type of pointcuts/advices we have matters, let me know (I will have a look into sources, haven't seen them yet).
Comment 13 Andrew Clement CLA 2014-08-20 15:02:14 EDT
Is there any chance you could share with me (privately?) the compiled class in question so I can take a look at the bytecode?