Bug 108894 - Always Implement Instanceof Test for Args
Summary: Always Implement Instanceof Test for Args
Status: RESOLVED DUPLICATE of bug 68603
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0 M4   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-06 22:29 EDT by Ron Bodkin CLA
Modified: 2005-09-09 06:48 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2005-09-06 22:29:34 EDT
public aspect InstanceOfArgs {
    private static Map val;
    private static Object pval;

    public static void main(String args[]) {
	setVal(null);
	setMap(null);
	val = null;
	pval = null;
	val = new HashMap();
    }

    public static void setVal(Object aVal) {
        val = (Map)aVal;
    }

    public static void setMap(Map aVal) {
        val = aVal;
    }

    void around(Map map) : set(* *.*) && args(map) {
	System.out.println("around set firing for "+map+" 
at "+thisJoinPoint+", "+thisJoinPoint.getSourceLocation());
	proceed(map);
    }

    void around(Map map) : call(* set*(*)) && args(map) {
	System.out.println("around call firing for "+map+" at "+thisJoinPoint);
	proceed(map);
    }

}

Actual Output
around set firing for null at set(Map InstanceOfArgs.val), InstanceOfArgs.aj:16
around call firing for null at call(void InstanceOfArgs.setMap(Map))
around set firing for null at set(Map InstanceOfArgs.val), InstanceOfArgs.aj:20
around set firing for null at set(Map InstanceOfArgs.val), InstanceOfArgs.aj:10
around set firing for {} at set(Map InstanceOfArgs.val), InstanceOfArgs.aj:12

Expected output:
around set firing for {} at set(Map InstanceOfArgs.val), InstanceOfArgs.aj:12
Comment 1 Adrian Colyer CLA 2005-09-08 04:19:43 EDT
this is an old chestnut. I'm marking M4 so that I make sure to come back and
respond properly
Comment 2 Adrian Colyer CLA 2005-09-09 06:48:09 EDT
AspectJ is working as designed here. If null did not match, writing advice that
checked for null arguments etc. would not be possible. The semantics are that
null matches iff the static type of the argument guarantees that any argument is
an instance of the target type without the need for a runtime check.

Thus the sets for val (of type Map) all match, because a field of type Map is
guaranteed to have a (possibly null) Map argument. The sets for pval do not
match as a field of type Object is not guaranteed to have a Map argument.

See the rigourous defence of these semantics by Erik in bug 68603.

*** This bug has been marked as a duplicate of 68603 ***