Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 408230

Summary: [1.8][hovering] NPE on hovering over a type inferred parameter in lambda expression
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: CoreAssignee: ANIRBAN CHAKRABORTY <anchakrk>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: anchakrk, manju656, markus.kell.r, srikanth_sankaran
Version: 4.3   
Target Milestone: BETA J8   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 408937, 409253    
Attachments:
Description Flags
patch for the fix
none
patch for the fix accommodating the review comments anchakrk: review?

Description Noopur Gupta CLA 2013-05-16 08:33:26 EDT
Consider the following example and hover on "a" as mentioned in the comments:

public class C1 {	
	FI i1= (a) -> a++; // [1] Hover on "a" in "a++"
	void foo() {
		FI i2= (a) -> {
			return a; // [2] Hover on "a"
		};
	}
}
interface FI {
	int f1(int a);
}

We get these exceptions:
[1]
java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.util.Util.typeSignature(Util.java:2685)
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptLocalVariable(SelectionRequestor.java:454)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:1229)

[2]
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:187)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:114)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:594)
Comment 1 Srikanth Sankaran CLA 2013-05-16 10:50:38 EDT
Thanks for the report Noopur, I'll take a look.
Comment 2 Srikanth Sankaran CLA 2013-07-22 04:04:01 EDT
Anirban, please follow up, TIA.
Comment 3 ANIRBAN CHAKRABORTY CLA 2013-07-29 23:30:18 EDT
Created attachment 233920 [details]
patch for the fix

patch for the fix
Comment 4 Srikanth Sankaran CLA 2013-08-01 04:56:45 EDT
Here are some review comments:

(1) loop iteration variables are best named i, j, k etc, instead of
indx.

(2) Always hoist the extraction of length of arrays outside the loop.

(3) In the following:

// ---
public class C1 {	
	void goo(FI f1) {
		
	}
//	FI i1= (a) -> a++; // [1] Hover on "a" in "a++"
	void foo() {
//		Object i2 = new Object() {
//			int foo (int a) {
//				return a; // [2] Hover on "a"
//			};
//		};
			FI i2= (a) -> {
				int b = a;
				return a; // [2] Hover on "a"
			};
			
			goo((a) -> a++);
			
			
		
	}
}
interface FI {
	int f1(int a);
}


hovering on either
goo((a) -> a++); or
return a

does not produce expected behavior.
Comment 5 Martin Mathew CLA 2013-09-20 08:19:28 EDT
bug 383096 looks partly similar to this bug as it has the similar exception stack trace as that of the second scenario.
Comment 6 ANIRBAN CHAKRABORTY CLA 2013-10-08 07:00:56 EDT
Created attachment 236207 [details]
patch for the fix accommodating the review comments

Hello,

Patch, which complies with http://www.eclipse.org/legal/CoO.php, is attached.

Among other things, one point to be noted is, while hovering on a lambda expression in an invocation context, the complete function (MessageSend) is not available up-to that point. Hence some reasonable heuristic is applied to find candidate(s) and the corresponding functional interface at that parameter number.

Thanks
Anirban
Comment 7 ANIRBAN CHAKRABORTY CLA 2013-10-08 14:43:22 EDT
(In reply to Manju Mathew from comment #5)
> bug 383096 looks partly similar to this bug as it has the similar exception
> stack trace as that of the second scenario.

No, that is a different issue. Thx
Comment 8 Srikanth Sankaran CLA 2013-10-10 12:35:27 EDT
Thanks for the patch Anirban - it is going to take me a week to 10 days
to get to this, appreciate your patience.
Comment 9 Srikanth Sankaran CLA 2013-11-14 06:30:42 EST
(In reply to Srikanth Sankaran from comment #8)
> Thanks for the patch Anirban - it is going to take me a week to 10 days
> to get to this, appreciate your patience.

Going to need 2-3 more weeks - Thanks for your patience.
Comment 10 Srikanth Sankaran CLA 2013-11-25 06:28:38 EST
I leveraged some elements from the proposed patch and redid parts of it
to integrate well with the existing scheme of affairs and released it here:
http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=a0893fa670a9452a3bb55e34d39061d0e31c358a.