Bug 371446

Summary: ClassCastException when advice is conditioned by @DeclareMixing and pointcut on method with argument
Product: [Tools] AspectJ Reporter: art y <artymt>
Component: LibraryAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Sample project to reproduce problem none

Description art y CLA 2012-02-14 01:22:10 EST
Build Identifier: Version: Indigo Service Release 1, Build id: 20110916-0149, Version: 2.1.3.e37x-20110628-1900, AspectJ version: 1.6.12.20110613132200

ClassCastException is thrown due to that AspectJ seems to confuse argument for cross-cut method and for @DeclareMixing inter-type.

For an example, by the following definitions, the ClassCastException is thrown as the stack traces appended below.

public static class MixeeClass1 extends ForDeclareMixin {
	public MixeeClass1( String omStr) {
		super();
		this.omStr = omStr;
	}
}

public static class MixinClass implements MixinInterface {
	ForDeclareMixin forDeclareMixin = null;
	
	public MixinClass( ForDeclareMixin forDeclareMixin) {
		this.forDeclareMixin = forDeclareMixin;
	}
	
	public void mixinInterfaceMethod() {
	}
}

@DeclareMixin( value="aspectJTest.DeclareMixinAspect.MixeeClass1")
public static MixinInterface addMixinInterfaceInterface( Object instance) {
	return new MixinClass( (MixeeClass1)instance);
}

@Around( 
	value="execution( * aspectJTest.ForDeclareMixin+.setOmStr( java.lang.String)) " 
			+ "&& this( mixinInterface)"
	)
public Object aroundAdvisedOMethod( 
		ProceedingJoinPoint proceedingJoinPoint, MixinInterface mixinInterface) {
			
	try {
		return proceedingJoinPoint.proceed( proceedingJoinPoint.getArgs());
	}
	catch( Throwable throwable) {
		if ( throwable instanceof RuntimeException) {
			throw (RuntimeException)throwable;
		}
		else {
			throw new RuntimeException( throwable);
		}
	}
}


java.lang.ClassCastException: java.lang.String cannot be cast to aspectJTest.ForDeclareMixin
	at aspectJTest.ForDeclareMixin.setOmStr_aroundBody1$advice(ForDeclareMixin.java:66)
	at aspectJTest.ForDeclareMixin.setOmStr(ForDeclareMixin.java:1)
	at aspectJTest.DeclareMixingTest.testDeclareMixing(DeclareMixingTest.java:31)


Reproducible: Always

Steps to Reproduce:
1. Import DeclareMixingClassCastExceptionTest project from attached DeclareMixingClassCastExceptionTest.zip file
2. Run testDeclareMixing test method in DeclareMixingTest class.
Comment 1 art y CLA 2012-02-14 01:24:05 EST
Created attachment 210952 [details]
Sample project to reproduce problem