Bug 124399 - AJDT AspectJ Internal Compiler Error
Summary: AJDT AspectJ Internal Compiler Error
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: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 130720 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-18 16:59 EST by Macneil Shonle CLA
Modified: 2006-03-10 11:29 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 Macneil Shonle CLA 2006-01-18 16:59:18 EST
In Eclipse 3.1.1 with AJDT 1.3 (the December 20th 2005 release) I got this message in an error dialog:

org.aspectj.weaver.BCException
at org.aspectj.weaver.bcel.LazyClassGen.getLazyMethodGen(LazyClassGen.java:1216)
at org.aspectj.weaver.bcel.LazyClassGen.getLazyMethodGen(LazyClassGen.java:1201)
at org.aspectj.weaver.bcel.BcelShadow.weaveAroundInline(BcelShadow.java:2048)
at org.aspectj.weaver.bcel.BcelAdvice.implementOn(BcelAdvice.java:232)
at org.aspectj.weaver.Shadow.implementMungers(Shadow.java:588)
at org.aspectj.weaver.Shadow.implement(Shadow.java:405)
at org.aspectj.weaver.bcel.BcelClassWeaver.implement(BcelClassWeaver.java:2146)
at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:467)
at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:102)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1543)
at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump(BcelWeaver.java:1494)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1275)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1097)
at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.weave(AjCompilerAdapter.java:300)
at org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterCompiling(AjCompilerAdapter.java:178)
at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:70)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:367)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:811)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:254)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild(AjBuildManager.java:163)
at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:117)
at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)

trouble in: 
public class edu.ucsd.aosd.MyApplication extends java.lang.Object:
  public void <init>():
                    ALOAD_0     // edu.ucsd.aosd.MyApplication this   (line 5)
                    INVOKESPECIAL java.lang.Object.<init> ()V
    constructor-execution(void edu.ucsd.aosd.MyApplication.<init>())
    |               RETURN
    constructor-execution(void edu.ucsd.aosd.MyApplication.<init>())
  end public void <init>()

  public static void main(String[])    org.aspectj.weaver.MethodDeclarationLineNumber: 8:124
:
    method-execution(void edu.ucsd.aosd.MyApplication.main(java.lang.String[]))
    |               ALOAD_0     // java.lang.String[] args   (line 9)
    |               ASTORE 4
    |               ICONST_0
    |               ISTORE_2
    |               ALOAD 4
    |               ARRAYLENGTH
    |               ISTORE_3
    |               GOTO L1
    |           L0: ALOAD 4
    |               ILOAD_2
    |               AALOAD
    |               ASTORE_1
    |               GETSTATIC java.lang.System.out Ljava/io/PrintStream;   (line 10)
    |               NEW java.lang.StringBuilder
    |               DUP
    |               LDC "got: "
    |               INVOKESPECIAL java.lang.StringBuilder.<init> (Ljava/lang/String;)V
    |               ALOAD_1     // java.lang.String arg
    | method-call(java.lang.StringBuilder java.lang.StringBuilder.append(java.lang.String))
    | |             INVOKEVIRTUAL java.lang.StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
    | method-call(java.lang.StringBuilder java.lang.StringBuilder.append(java.lang.String))
    | method-call(java.lang.String java.lang.StringBuilder.toString())
    | |             INVOKEVIRTUAL java.lang.StringBuilder.toString ()Ljava/lang/String;
    | method-call(java.lang.String java.lang.StringBuilder.toString())
    |               ASTORE 5
    |               ASTORE 6
    | method-call(void java.io.PrintStream.println(java.lang.String))
    | |             ALOAD 6
    | |             ALOAD 5
    | |             INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V
    | method-call(void java.io.PrintStream.println(java.lang.String))
    |               GETSTATIC java.lang.System.out Ljava/io/PrintStream;   (line 11)
    |               LDC "got: %s\n"
    |               ICONST_1
    |               ANEWARRAY java.lang.Object
    |               DUP
    |               ICONST_0
    |               ALOAD_1     // java.lang.String arg
    |               AASTORE
    | method-call(java.io.PrintStream java.io.PrintStream.printf(java.lang.String, java.lang.Object[]))
    | |             INVOKEVIRTUAL java.io.PrintStream.printf (Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream;
    | method-call(java.io.PrintStream java.io.PrintStream.printf(java.lang.String, java.lang.Object[]))
    |               POP
    |               IINC 2 1   (line 9)
    |           L1: ILOAD_2
    |               ILOAD_3
    |               IF_ICMPLT L0
    |               RETURN   (line 13)
    method-execution(void edu.ucsd.aosd.MyApplication.main(java.lang.String[]))
  end public static void main(String[])

end public class edu.ucsd.aosd.MyApplication

when implementing on shadow method-call(void java.io.PrintStream.println(java.lang.String))
when weaving type edu.ucsd.aosd.MyApplication
when weaving classes 
when weaving 
when incrementally building BuildConfig[C:\EclipseWorkspace\.metadata\.plugins\org.eclipse.ajdt.core\AspectJSemanticsTest.generated.lst] #Files=2

It occured when I editing this file, in an AspectJ project with an recently renamed .aj extension:

package edu.ucsd.aosd;

import java.io.PrintStream;

public class MyApplication
{
    // main
    public static void main(String[] args) {
        for (String arg : args) {
            System.out.println("got: " + arg);
            System.out.printf("got: %s\n", arg);
        }
    }
}

aspect Printing {
    pointcut printlnCalls(PrintStream ps, String out):
        call(* PrintStream+.println(String)) && target(ps) && args(out);
    Object around(PrintStream ps, String out):
        printlnCalls(ps, out) && !adviceexecution() {
        return proceed(ps, out);
    }
    
    pointcut printfCalls(PrintStream ps, String fmt, Object[] objs):
        call(* PrintStream+.printf(String, Object...#####))
        && target(ps) && args(fmt, objs);
}

Where "#####" is where my cursor was when I saved. My previously saved version didn't have the printfCalls pointcut nor the call to printf in the main. (Thus, you might want to try the println version first, save it, and then make the new additions. Though, I hope the debug information is enough.)
Comment 1 Andrew Clement CLA 2006-01-24 05:00:29 EST
hmmm.  I added a testcase for this to the harness we have for exercising incremental compilation - works for me :(   I created the version without the printf pointcut then added that and performed an inc-compile.  The test is commented out for now (even though it works) until someone gets more time to play around and investigate this bug.  I believe we don't have any test programs that use printf() so wouldnt be surprised if there was some kind of problem...
Comment 2 Helen Beeken CLA 2006-01-30 08:16:49 EST
I've spent some time trying to recreate this problem and so far have had no success...

In the output it says that it's building two files - is it possible to attach the other file to this bug?

(As a note the failing line number is 1230 in the latest codebase in HEAD).
Comment 3 Macneil Shonle CLA 2006-01-30 13:38:06 EST
Here's the other file, which is a pure .java file:

package edu.ucsd.aosd;

import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

public class GenericsMapTest
{
    public interface BinaryFunction<T>
    {
        T apply(T x, T y);
    }

    public interface UnaryFunction<T>
    {
        T apply(T x);
    }

    // main
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(new Integer[]{1,2,3,4,5});
        Integer sum = reduce(list, 0, new BinaryFunction<Integer>() {
            public Integer apply(Integer x, Integer y) {
                return x + y;
            }
        });
        applyAll(list, new UnaryFunction<Integer>() {
            public Integer apply(Integer x) {
                return x * x;
            }
        });
        System.out.printf("sum = %d\n", sum);
        for (Integer i: list) {
            System.out.printf("%d ", i);
        }
    }

    static <T> T reduce(List<T> list, T identity, BinaryFunction<T> fun) {
        T result = identity;
        for (T item: list) {
            result = fun.apply(result, item);
        }
        return result;
    }

    static <T> void applyAll(List<T> list, UnaryFunction<T> fun) {
        ListIterator<T> it = list.listIterator();
        while (it.hasNext()) {
            it.set(fun.apply(it.next()));
        }
    }
}

####
Unfortunately I don't recall the order in which I typed in things, made errors, resaved/recompiled, changed the other .java file to .aj, et cetera... I assume order is important for this. I'll add anything else if it happens again.
Comment 4 Helen Beeken CLA 2006-02-13 11:38:57 EST
I've still not had any success reproducing this bug, although as a note the reason for the BCExcpetion is that the LazyMethodGen associated with the around advice is no longer in the list of methodGens for the aspect....how or why this happened I don't know and can't investigate further until I reproduce it.

However, since the changes entitled "go 'back to source' on incremental aspect change" were checked in to HEAD, the testcase for this bug which Andy checked in and commented out (mentioned in comment #1) is now failing because the changes now force a full build rather than an incremental one. Therefore, I don't believe that the failing scenario described in this bug can be reproduced since any change to the aspect or class within MyApplication now results in a full build and the problem is an incremental one.
Comment 5 Andrew Clement CLA 2006-03-07 05:57:14 EST
*** Bug 130720 has been marked as a duplicate of this bug. ***
Comment 6 Helen Beeken CLA 2006-03-10 11:29:01 EST
Closing this bug as fixed as per the comment #4. The scenario described in this bug can no longer happen as any changes made to aspects now results in us going back to the source and doing a full build, whereas this bug was seen on an incremental build after changes to an aspect. This is available in the latest AJDT 1.3.1 dev build and will be available in the next AJDT 1.4 dev build.