Bug 72668 - Incompatible return type applying to method-execuition...
Summary: Incompatible return type applying to method-execuition...
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-26 06:26 EDT by Rohith Ajjampur CLA
Modified: 2005-08-25 04:37 EDT (History)
0 users

See Also:


Attachments
Contains test code (1.40 KB, application/x-zip-compressed)
2004-08-26 06:29 EDT, Rohith Ajjampur CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rohith Ajjampur CLA 2004-08-26 06:26:16 EDT
Probably related to Bug 72528, i get the above said error while compiling the
test code, i think this is caused due to the return type of a method being an
Integer[] and the around advice captures it and returns an Object[]. Below is
the complete error message:
Incompatible return type applying to method-execuition(java.lang.Integer[]
de.rohith.PrinterWorld.returnArrayWithCloning())
Incompatible return type applying to method-execuition(java.lang.Integer[]
de.rohith.PrinterWorld.returnArrayWithoutCloning()).
Comment 1 Rohith Ajjampur CLA 2004-08-26 06:29:34 EDT
Created attachment 14186 [details]
Contains test code
Comment 2 Adrian Colyer CLA 2004-09-08 08:18:06 EDT
Assigning to Andy for consideration whilst working on the related bug.
Comment 3 Adrian Colyer CLA 2005-03-22 09:26:15 EST
any verifyerror is serious, this should be fixed in AJ5 M3...
Comment 4 Adrian Colyer CLA 2005-08-25 04:37:57 EDT
Finally managed to give this bug a closer examination, and realised that this
isn't a bug at all - AspectJ is working as designed.

The reason is that the returnArrayWithCloning method has a contract that says it
will return an Integer[], but your around advice has a contract that says it
will return an Object[]. Thus the return type of the advice does not guarantee
to meet the contract of the advised method. 

The following short program demonstrates this:

public aspect pr72668 {
	
	Number[] getThoseInts() {
		return new Integer[0];
	}
	
	declare warning : execution(Object[] *(..)) : "should not match";
	
	@org.aspectj.lang.annotation.SuppressAjWarnings("adviceDidNotMatch")
	Object[] around() : execution(*[] *(..)) {
		Object[] ret = proceed();
		return (Object[]) ret.clone();
	}
	
	Integer[] around() : execution(*[] *(..)) {
		Number[] ret = proceed();
		return (Integer[]) ret.clone();
	}
	
}

The advice returning Object[] does not match at the shadow and gives an
incompatible return type error. The advice returning Integer[] does match,
because an Integer[] is guaranteed to meet the contract of a method that returns
a Number[].