Bug 332388 - ajc failure when classpath is missing generic type parameter
Summary: ajc failure when classpath is missing generic type parameter
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.10   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 1.6.11   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-12 05:08 EST by Trask Stalnaker CLA
Modified: 2010-12-14 18: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 Trask Stalnaker CLA 2010-12-12 05:08:54 EST
Build Identifier: 1.6.10

I tried to upgrade from 1.6.8 to 1.6.10 and ran into this issue.

It fails in 1.6.9, 1.6.10 and 1.6.11.m1.  It works in 1.6.8.

An ajcore file is generated pointing to

 -- (ClassCastException) org.aspectj.weaver.MissingResolvedTypeWithKnownSignature cannot be cast to org.aspectj.weaver.ReferenceType
org.aspectj.weaver.MissingResolvedTypeWithKnownSignature cannot be cast to org.aspectj.weaver.ReferenceType
java.lang.ClassCastException: org.aspectj.weaver.MissingResolvedTypeWithKnownSignature cannot be cast to org.aspectj.weaver.ReferenceType
	at org.aspectj.weaver.TypeVariableReferenceType.getDelegate(TypeVariableReferenceType.java:44)
	at org.aspectj.weaver.ReferenceType.getTypeVariables(ReferenceType.java:810)
	at org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.fixUpCircularDependencies(BcelGenericSignatureToTypeXConverter.java:231)
	at org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(BcelGenericSignatureToTypeXConverter.java:180)
	at org.aspectj.weaver.bcel.BcelMethod.unpackGenericSignature(BcelMethod.java:564)
	at org.aspectj.weaver.bcel.BcelMethod.getGenericReturnType(BcelMethod.java:497)
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:756)
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:709)
	at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:766)
	at org.aspectj.weaver.ResolvedType.lookupMethod(ResolvedType.java:534)
	at org.aspectj.weaver.World.resolve(World.java:626)
	...


Reproducible: Always

Steps to Reproduce:
I have been able to reduce this to following minimal repro (these steps generate an ajcore file in 1.6.9, 1.6.10 and 1.6.11.m1, while the same steps succeed in 1.6.8):

public class M {}

public class A<T extends M> {
    public void a(T t) {
    }
}

public class B<T extends M> extends A<T> {
    public void b() {
        a(null);
    }
}

@Aspect
public class MyAspect {

    @Before("call(* *.*(..))")
    public void myAdvice() {
        System.out.println();
    }
}

javac M.java A.java B.java
jar cf M.jar M.class
jar cf AB.jar A.class B.class

javac -classpath %ASPECTJ_HOME%\lib\aspectjrt.jar MyAspect.java
jar cf aspects.jar MyAspect.class

%ASPECTJ_HOME%\bin\ajc -1.5 -inpath AB.jar -aspectpath aspects.jar -outjar out.jar -classpath %ASPECTJ_HOME%\lib\aspectjrt.jar
Comment 1 Andrew Clement CLA 2010-12-13 01:52:08 EST
thanks for the testcase!
Comment 2 Trask Stalnaker CLA 2010-12-13 04:19:17 EST
No problem, thanks for targeting to 1.6.11.

I ran into one more that is a slightly different pattern (though same exception in ajcore file).

This repro, however, fails on both 1.6.10 and 1.6.8.  Not sure where I went wrong when I reduced this repro (in my full environment it only fails on 1.6.10), but I'm happy to test a patch or dev build when available to validate in my full environment.

public class M {}

public class A<T> {

    public void a(Class<? extends M> list) {}

    public void x() {
        a(null);
    }
}

@Aspect
public class MyAspect {

    @Before("call(* *.*(..)) && target(x)")
    public void myAdvice(CharSequence x) {
		System.out.println();
    }
}

javac M.java A.java
jar cf M.jar M.class
jar cf A.jar A.class

javac -g -classpath %ASPECTJ_HOME%\lib\aspectjrt.jar MyAspect.java
jar cf aspects.jar MyAspect.class

%ASPECTJ_HOME%\bin\ajc -1.5 -inpath A.jar -aspectpath aspects.jar -outjar out.jar -classpath %ASPECTJ_HOME%\lib\aspectjrt.jar
Comment 3 Andrew Clement CLA 2010-12-13 15:31:58 EST
both of these fixed in HEAD now (with regression tests).  Likely to be a couple more similar scenarios as we don't have all the checks in place to make sure the type is found before treating it as a ReferenceType.
Comment 4 Trask Stalnaker CLA 2010-12-13 18:11:53 EST
Thanks for looking at it so quickly.  I tested it out.  Is there a way to make these test cases just generate a missing type warning and not terminate the weaving, similar to how some other missing types are handled and controllable via Xlint "cantFindType" (or something like that)?
Comment 5 Andrew Clement CLA 2010-12-14 15:35:03 EST
done, now xlints - of course you may get unpredictable results later in the process as the types are missing and bounds default to Object.
Comment 6 Trask Stalnaker CLA 2010-12-14 18:57:08 EST
I tested it against my full environment, looks good, thanks again.