Bug 271169 - BcelShadow.java:2354 ArrayIndexOutOfBoundsException when implementing on shadow method-call
Summary: BcelShadow.java:2354 ArrayIndexOutOfBoundsException when implementing on shad...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.6.5   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-03 14:26 EDT by Wolfgang Hospital CLA
Modified: 2009-04-04 14:42 EDT (History)
1 user (show)

See Also:


Attachments
pointcut & advice (2.06 KB, application/octet-stream)
2009-04-04 12:58 EDT, Wolfgang Hospital CLA
no flags Details
source file mentioned in the details of an eclipse error pop-up (7.21 KB, application/octet-stream)
2009-04-04 13:12 EDT, Wolfgang Hospital CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Hospital CLA 2009-04-03 14:26:50 EDT
(observed with I20080617-2000. To reproduce:)

1. use AspectJ 20090304172355
2. take a sizeable code base with heavily overloaded methods
3. create an around advice cutting across calls to the above
4. try and have the compiled classes woven

More information:
- 
In a separate proof-of-principle project in the same workspace, pointcut, advice and supporting classes seem to work as desired.

Some information from the "details" of a popup in eclipse on a debug launch of an instrumentation attempt for a trivial "main":
java.lang.ArrayIndexOutOfBoundsException
at org.aspectj.weaver.bcel.BcelShadow.weaveAroundInline(BcelShadow.java:2354)
at org.aspectj.weaver.bcel.BcelAdvice.implementOn(BcelAdvice.java:322)
at org.aspectj.weaver.Shadow.implementMungers(Shadow.java:613)
at org.aspectj.weaver.Shadow.implement(Shadow.java:527)
at org.aspectj.weaver.bcel.BcelClassWeaver.implement(BcelClassWeaver.java:3053)
at org.aspectj.weaver.bcel.BcelClassWeaver.weave(B ... .aspectj.runtime.internal.AroundClosure, org.aspectj.lang.JoinPoint$StaticPart)
end public abstract class com.iqdoq.hyperdoc.util.misc.HypChecksums
(the testrun commences without noticable malfunction)

from an ant run outside the eclipse IDE:
[...] trouble in: 
[javac-iajc] public class com.iqdoq.hyperdoc.server.doccleaner.test.HypCleanerTestUtil extends [... less than five thousand lines of blurb ...]
when implementing on shadow method-call(com.iqdoq.hyperdoc.server.doc.HypDocOutputStream com.iqdoq.hyperdoc.server.doc.HypDocManager.createDocStream(long, int[], long[], long, java.lang.Object, java.lang.String, java.lang.String, int, java.lang.String, java.sql.Timestamp, int, long, long))
[javac-iajc] when weaving classes 
[javac-iajc] when weaving 
[javac-iajc] when batch building BuildConfig[null] #Files=1143 AopXmls=#0
[javac-iajc] 18
[javac-iajc] java.lang.ArrayIndexOutOfBoundsException: 18
[javac-iajc] 	at org.aspectj.weaver.bcel.BcelShadow.weaveAroundInline(BcelShadow.java:2354)
[javac-iajc] 	at org.aspectj.weaver.bcel.BcelAdvice.implementOn(BcelAdvice.java:322)
[javac-iajc] 	at org.aspectj.weaver.Shadow.implementMungers(Shadow.java:613)
[javac-iajc] 	at org.aspectj.weaver.Shadow.implement(Shadow.java:527) [ad nauseam]


The error on HypChecksums is interesting, as that class is empty but for a nested interface, two nested classes and a twenty-line main().
Memory limit is above 1GB (eclipe footprint, too).

(For a first application, I worked around this excluding types where this occurred from the point cut explicitly. Murphy assured the second application is in one of these.)
Comment 1 Andrew Clement CLA 2009-04-04 01:14:00 EDT
looks like the change to produce more comprehensive local variable tables for generated methods has led to this failure.
Comment 2 Wolfgang Hospital CLA 2009-04-04 12:17:03 EDT
from a peek at the source, I don't get how extraParamOffset is related to
Type[] args = localAdviceMethod.getArgumentTypes() -
for (int slot = 0; slot < args.length; i++)?
Comment 3 Andrew Clement CLA 2009-04-04 12:26:28 EDT
i just can't recreate this problem.  I tried a very pervasive aspect applying to a ton of code and it doesn't fail.

Any way you can share the failing code with me?  

If you can't share .class files - can you 'javap -verbose -private HypCheckSums' and show me all the local variable tables - that may help.

> Type[] args = localAdviceMethod.getArgumentTypes() -
> for (int slot = 0; slot < args.length; i++)?

i hate that loop, it needs rewriting, but I don't want to change it if I have no idea why it is failing.
Comment 4 Andrew Clement CLA 2009-04-04 12:41:15 EDT
The around advice signature and related pointcut would be extremely useful too.  What are you binding? args? this? target? none of them? Are you using thisJoinPoint/thisJoinPointStaticPart in the advice?
Comment 5 Wolfgang Hospital CLA 2009-04-04 12:58:18 EDT
Created attachment 130920 [details]
pointcut & advice

((problably useless) source code coming rsn)
(I *detest* the pressure to enable scripting - are there saner interfaces to buzilla?)
Comment 6 Wolfgang Hospital CLA 2009-04-04 13:12:25 EDT
Created attachment 130921 [details]
source file mentioned in the details of an eclipse error pop-up

Inclusion of this file in the abovementioned pop-project has _not_ triggered the problem.

(Publishing the 8-digit bytes of product code looks a problem in general
- this file contains PD C source, mostly)
Comment 7 Andrew Clement CLA 2009-04-04 13:22:59 EDT
recreated it! thanks for the code.
Comment 8 Andrew Clement CLA 2009-04-04 13:31:34 EDT
Ok - this fails in the same way:
---
public class HypChecksums {
 
  static class Adler {
    long combine(long a, long b, long c, long d) {
      return 3;
    }
  } 

  public static void main(final String[] pArgs) {
    Adler comb = new Adler();
    comb.combine(4, 2, 3, 3);
  }
}

aspect X { 
	Object around(): call(* combine(..)) && !within(X) {
		return proceed();
	}
}
---
Comment 9 Andrew Clement CLA 2009-04-04 14:42:34 EDT
the problem was increasing the slot size using the slot number as the index into the argument array.  The argument index should be used.  It doesn't matter (the indexes will be the same) unless double slot parameter types are being used, like long.  Once they get out of step, the local variable table will be wrong but this won't necessarily lead to a failure (just look wierd when debugging).  But if enough double slot parameter types are used then it will fail at weave time due to running out of array entries.

Here the use of 4 longs causes us to jump right off the end of the array.  3 longs doesn't fail.

test and fix committed.  will be in todays AspectJ dev build.