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

Erik H. suggested that I also test the case where you call a method with a
parameter that's statically resolvable to the type (Map). That also fails! I
also realized that my test program was shadowing the static fields in the
setters (this doesn't affect the inconsistency, but fixing it makes the
situation clearer). Here's the resulting program & output:

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);
    }

    //before() : set(* *.*) && if(thisJoinPoint.getArgs()[0] == null) {
	//System.out.println("null set for map at "+thisJoinPoint);
    //}

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

}

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


-----Original Message-----
From: aspectj-dev-bounces@xxxxxxxxxxx
[mailto:aspectj-dev-bounces@xxxxxxxxxxx] On Behalf Of Ron Bodkin
Sent: Monday, July 18, 2005 5: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