Project: AspectJ
Bug 148409 [generics] ClassCastException in UnresolvedType.java:348
Reported: 2006-06-23 12:29:03 | Status: resolved fixed

I am using AspectJ load time weaving with Spring 2.0 RC1 to inject my entities, and I am getting the following exception: java.lang.ClassCastException: org.aspectj.apache.bcel.classfile.Signature$TypeVariableSignature at org.aspectj.weaver.UnresolvedType.forGenericTypeSignature(UnresolvedType.java:348) at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:385) at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.accept(ClassLoaderWeavingAdaptor.java:492) at org.aspectj.weaver.tools.WeavingAdaptor.shouldWeave(WeavingAdaptor.java:230) 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:55) at sun.instrument.TransformerManager.transform(TransformerManager.java:122) at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155) at java.lang.ClassLoader.defineClass1(Native Method) . . . Having examined the call stack under the debugger, this seems to happening when the weaver is attempting to determine whether a particular class should be weaved. The exception is thrown in the following method, at the cast highlighted below. public static UnresolvedType forGenericTypeSignature(String sig,String declaredGenericSig) { UnresolvedType ret = UnresolvedType.forSignature(sig); ret.typeKind=TypeKind.GENERIC; ClassSignature csig = new GenericSignatureParser().parseAsClassSignature(declaredGenericSig); Signature.FormalTypeParameter[] ftps = csig.formalTypeParameters; ret.typeVariables = new TypeVariable[ftps.length]; for (int i = 0; i < ftps.length; i++) { Signature.FormalTypeParameter parameter = ftps[i]; Signature.ClassTypeSignature cts = (Signature.ClassTypeSignature)parameter.classBound; // EXCEPTION HERE! ret.typeVariables[i]=new TypeVariable(ftps[i].identifier,UnresolvedType.forSignature(cts.outerType.identifier+";")); } ret.signatureErasure = sig; ret.signature = ret.signatureErasure; return ret; } The class in question (which is not one that requires weaving), has the following signature: public class HibernateEntityDAO<interfaceT extends SecurityEntity, concreteT extends interfaceT> extends HibernateDaoSupport implements EntityDAO<interfaceT> The exception is happening because the parameter.classBound member is not of type Signature.ClassTypeSignature, but an instance of Signature.TypeVariableSignature. The loop variable i is 1, and parameter.identifier is concreteT, so it looks like it's the signature of the second type parameter (concreteT) that is tripping up the weaver.

Files changed in fix:
tests/bugs153/pr148409/Blurgh.java tests/bugs153/pr148409/X.java tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java weaver/src/org/aspectj/weaver/UnresolvedType.java