Bug 371446 - ClassCastException when advice is conditioned by @DeclareMixing and pointcut on method with argument
Summary: ClassCastException when advice is conditioned by @DeclareMixing and pointcut ...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Library (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-14 01:22 EST by art y CLA
Modified: 2012-02-14 01:24 EST (History)
0 users

See Also:


Attachments
Sample project to reproduce problem (10.48 KB, application/octet-stream)
2012-02-14 01:24 EST, art y CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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