Bug 489138 - pointcut on java8 method reference not works
Summary: pointcut on java8 method reference not works
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.8.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-07 09:27 EST by hui Deng CLA
Modified: 2016-03-07 11:48 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hui Deng CLA 2016-03-07 09:27:10 EST
suppose pointcut: 
    this(classpath.to.T1) && call(* classpath.to.T2.get*(..))
following codes in T1 Class work:
    T2 t2=new T2();
    t2.getSomething(); // this line is advised
but following code in T1 Class don't work:
    someT1Function(t2::getSomething) //this method reference is not advised
Comment 1 Andrew Clement CLA 2016-03-07 11:48:49 EST
A method reference is not a method call though is it? So I wouldn't expect that to match. It is just a reference to a method that is being passed around.  Whatever code you pass it to, if you make a call through its receiving functional interface parameter, you could catch that call:

public class YY {
	public static void main(String[] args) {
		new YY().run(YY::m);
	}
	
	public void run(SomeFunctionalInterface sfi) {
		sfi.foo();
	}

	public static void m() {
	}
}

interface SomeFunctionalInterface {
	void foo();
}

aspect X {
	before(): call(* foo(..)) {
		System.out.println("Called!");
	}
}

Here the advice catches the call to foo() made in the run() method, but we can't currently tell it is being satisfied by a method called 'm' that was passed in by reference.