Bug 121575 - [generics]"abort trouble" when loading generic class using loadtime weaving
Summary: [generics]"abort trouble" when loading generic class using loadtime weaving
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0RC2   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: 2005-12-20 11:11 EST by Calum MacLean CLA
Modified: 2006-02-15 06:18 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Calum MacLean CLA 2005-12-20 11:11:29 EST
I'm getting an "abort trouble in" error message when using load-time weaving.  My class is a generic class - the error message says "Wrong number of type parameters supplied", so I think it's something to do with my class being generic.

BTW, this is against the released version of AJ - Version field in bug report form just has M5, RC1, RC2 etc.

I have the following class and interface (pruned down):

--- START com/mycompany/MyClass.java ---

package com.mycompany;

import java.io.*;

class MyClass<T,E> implements MyInterface<T>
{
    public static void main(String[] arg)
    {
    }

    public T read()
        throws IOException
    {
        return null;
    }

    public void exceptionDetected(E e)
    {
    }
}

interface MyInterface<T>
{
    public T read()
        throws IOException;
}

--- END com/mycompany/MyClass.java ---

Here's my aop.xml:

--- START META-INF/aop.xml ---

<aspectj>

    <aspects>
        <aspect name="com.mycompany.MyAspect"/>
    </aspects>

    <weaver/>

</aspectj>

--- END META-INF/aop.xml ---

Here's my Aspect (using @AJ):

--- START com/mycompany/MyAspect.java ---

package com.mycompany;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MyAspect
{
    @Pointcut("execution(* com.mycompany.MyOtherClass.read())")
    void myPointcut()
    {
    }

    @Before("myPointcut()")
    public void myAdvice()
    {
        System.out.println("read()");
    }
}

--- END com/mycompany/MyAspect.java ---

And here's another class which is referenced in the aspect:

--- START com/mycompany/MyOtherClass.java ---

package com.mycompany;

class MyOtherClass
{
    public void read()
    {
    }
}

--- END com/mycompany/MyOtherClass.java ---

When I run MyClass (it's got a main method), I get an error reported as attached below.

When I change the aspect to reference MyClass instead of MyOtherClass, no error message is reported.

BTW, I can't any way to have attachments to a bug report - is what I've done the correct way to do it?

Thanks,
Calum

--- START OUTPUT ---

abort trouble in: 
 class com.mycompany.MyClass extends java.lang.Object implements com.mycompany.MyInterface:
  void <init>():
                    ALOAD_0     // com.mycompany.MyClass this   (line 5)
                    INVOKESPECIAL java.lang.Object.<init> ()V
    constructor-execution(void com.mycompany.MyClass.<init>())
    |               RETURN
    constructor-execution(void com.mycompany.MyClass.<init>())
  end void <init>()

  public static void main(String[]):
                    RETURN   (line 9)
  end public static void main(String[])

  public Object read() throws java.io.IOException:
                    ACONST_NULL   (line 14)
                    ARETURN
  end public Object read() throws java.io.IOException

  public void exceptionDetected(Object):
                    RETURN   (line 19)
  end public void exceptionDetected(Object)

end  class com.mycompany.MyClass
 -- (IllegalStateException) Wrong number of type parameters supplied
Wrong number of type parameters supplied
java.lang.IllegalStateException: Wrong number of type parameters supplied
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:609)
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:590)
	at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:421)
	at org.aspectj.weaver.ResolvedType.addAndRecurse(ResolvedType.java:262)
	at org.aspectj.weaver.ResolvedType.getMethodsWithoutIterator(ResolvedType.java:257)
	at org.aspectj.weaver.ResolvedType.lookupResolvedMember(ResolvedType.java:375)
	at org.aspectj.weaver.JoinPointSignatureIterator.findSignaturesFromSupertypes(JoinPointSignatureIterator.java:167)
	at org.aspectj.weaver.JoinPointSignatureIterator.hasNext(JoinPointSignatureIterator.java:68)
	at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:286)
	at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:106)
	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:145)
	at org.aspectj.weaver.patterns.AndPointcut.matchInternal(AndPointcut.java:55)
	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:145)
	at org.aspectj.weaver.ShadowMunger.match(ShadowMunger.java:64)
	at org.aspectj.weaver.Advice.match(Advice.java:109)
	at org.aspectj.weaver.bcel.BcelAdvice.match(BcelAdvice.java:104)
	at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:2113)
	at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:1713)
	at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:455)
	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.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:277)
	at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:210)
	at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:65)
	at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:52)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:122)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:83)

Message: abort trouble in: 
 class com.mycompany.MyClass extends java.lang.Object implements com.mycompany.MyInterface:
  void <init>():
                    ALOAD_0     // com.mycompany.MyClass this   (line 5)
                    INVOKESPECIAL java.lang.Object.<init> ()V
    constructor-execution(void com.mycompany.MyClass.<init>())
    |               RETURN
    constructor-execution(void com.mycompany.MyClass.<init>())
  end void <init>()

  public static void main(String[]):
                    RETURN   (line 9)
  end public static void main(String[])

  public Object read() throws java.io.IOException:
                    ACONST_NULL   (line 14)
                    ARETURN
  end public Object read() throws java.io.IOException

  public void exceptionDetected(Object):
                    RETURN   (line 19)
  end public void exceptionDetected(Object)

end  class com.mycompany.MyClass
 -- (IllegalStateException) Wrong number of type parameters supplied
Wrong number of type parameters supplied
java.lang.IllegalStateException: Wrong number of type parameters supplied
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:609)
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:590)
	at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:421)
	at org.aspectj.weaver.ResolvedType.addAndRecurse(ResolvedType.java:262)
	at org.aspectj.weaver.ResolvedType.getMethodsWithoutIterator(ResolvedType.java:257)
	at org.aspectj.weaver.ResolvedType.lookupResolvedMember(ResolvedType.java:375)
	at org.aspectj.weaver.JoinPointSignatureIterator.findSignaturesFromSupertypes(JoinPointSignatureIterator.java:167)
	at org.aspectj.weaver.JoinPointSignatureIterator.hasNext(JoinPointSignatureIterator.java:68)
	at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:286)
	at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:106)
	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:145)
	at org.aspectj.weaver.patterns.AndPointcut.matchInternal(AndPointcut.java:55)
	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:145)
	at org.aspectj.weaver.ShadowMunger.match(ShadowMunger.java:64)
	at org.aspectj.weaver.Advice.match(Advice.java:109)
	at org.aspectj.weaver.bcel.BcelAdvice.match(BcelAdvice.java:104)
	at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:2113)
	at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:1713)
	at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:455)
	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.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:277)
	at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:210)
	at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:65)
	at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:52)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:122)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:83)

org.aspectj.bridge.AbortException: trouble in: 
 class com.mycompany.MyClass extends java.lang.Object implements com.mycompany.MyInterface:
  void <init>():
                    ALOAD_0     // com.mycompany.MyClass this   (line 5)
                    INVOKESPECIAL java.lang.Object.<init> ()V
    constructor-execution(void com.mycompany.MyClass.<init>())
    |               RETURN
    constructor-execution(void com.mycompany.MyClass.<init>())
  end void <init>()

  public static void main(String[]):
                    RETURN   (line 9)
  end public static void main(String[])

  public Object read() throws java.io.IOException:
                    ACONST_NULL   (line 14)
                    ARETURN
  end public Object read() throws java.io.IOException

  public void exceptionDetected(Object):
                    RETURN   (line 19)
  end public void exceptionDetected(Object)

end  class com.mycompany.MyClass

	at org.aspectj.bridge.MessageWriter.handleMessage(MessageWriter.java:47)
	at org.aspectj.weaver.tools.WeavingAdaptor$WeavingAdaptorMessageHandler.handleMessage(WeavingAdaptor.java:411)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1554)
	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.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:277)
	at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:210)
	at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:65)
	at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:52)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:122)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:83)

--- END OUTPUT ---
Comment 1 Andrew Clement CLA 2005-12-20 11:33:09 EST
Thanks for the clear report - I prefer when you include the code inline rather than as attachments - but other committers may feel differently :)

And thanks for the pointer on not having 1.5.0 as a version against which bugs can be reported - I've submitted a request to eclipse.org to get that fixed.

Here is a smaller, standalone program that also fails in the same way, without LTW:

===8<================
import java.io.*;

aspect MyAspect {
    before(): execution(* MyOtherClass.read()) { }
}


class MyClass<T,E> implements MyInterface<T> {

    public static void main(String[] arg) { }

    public T read() throws IOException {
        return null;
    }

    public void exceptionDetected(E e) { }
}


interface MyInterface<T> {
    public T read() throws IOException;
}

class MyOtherClass {
    public void read() { }
}
===8<================

Comment 2 Andrew Clement CLA 2005-12-20 11:39:31 EST
as i suspected, the bug is related to using different numbers of type variables in the class and the interface.  What is being expressed is valid, but we don't cope well with it.  Changing MyInterface to add a redundant type variable is a workaround:

interface MyInterface<T,X> { 
  public T read() throws IOException;
}

class MyClass<T,E> implements MyInterface<T,E> {
...
}

Comment 3 Andrew Clement CLA 2005-12-21 06:47:03 EST
Fix checked in.  The problem is just parameterizing a types super interfaces using the collapsed bounds of the types own type variables - here the erasures for the type variables are Object and Object when the superinterface only takes one type parameter.  We now use the correct bounds for parameterizing the superinterface.  Possibly could do with more testcases that experiment in the area of parameterizing types with type variables.

fixes checked into HEAD.
Comment 4 Andrew Clement CLA 2006-02-15 06:18:52 EST
fix available.