Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-dev] Inconsistent Handling for args when null

Also, if you want to write advice on setting a field to a null value
predictably, with the semantics I believe are expected, you need to use
thisJoinPoint.getArgs() in the advice body, instead of binding with args.
Unlike in the case of this and target, I think this is somewhat surprising.

And if you'd like to just handle in a separate piece of advice, you get the
somewhat ugly  set(* *.*) && if(thisJoinPoint.getArgs()[0] == null);

-----Original Message-----
From: aspectj-dev-bounces@xxxxxxxxxxx
[mailto:aspectj-dev-bounces@xxxxxxxxxxx] On Behalf Of Ron Bodkin
Sent: Monday, July 18, 2005 2:30 PM
To: 'AspectJ developer discussions'
Subject: [aspectj-dev] Inconsistent Handling for args when null

Hi All,

We just ran into a case where AspectJ (both 1.2.1 and CVS HEAD) is
inconsistent in how it handles args on a field setter where there's a null
value. I believe args should *not* match if you set a value to null (also a
possible surprise/gotcha, but consistent with instanceof semantics).

The following test program fairly shows inconsistent behavior in my mind.
The output from this program is
around set firing for null at set(Map InstanceOfArgs.val)

I.e., just the one set to null matches, not the version that gets set
through a method call nor the version that is set on a field that isn't
statically determinable to be of type Map. I believe this program should
produce *no* output. I'd like to flag this for some discussion before
submitting to bugzilla.

import java.util.*;

public aspect InstanceOfArgs {
    private static Map val;
    private static Object pval;

    public static void main(String args[]) {
	setVal(null);
	val = null; // MATCHES!
	pval = null;
    }

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

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

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

}

Ron Bodkin
Chief Technology Officer
New Aspects of Software
w: (415) 824-4690


_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev




Back to the top