| 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: | Core | Assignee: | 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: |
|
||||||||
Thanks for the report Noopur, I'll take a look. Anirban, please follow up, TIA. Created attachment 233920 [details]
patch for the fix
patch for the fix
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.
bug 383096 looks partly similar to this bug as it has the similar exception stack trace as that of the second scenario. 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 (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 Thanks for the patch Anirban - it is going to take me a week to 10 days to get to this, appreciate your patience. (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. 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. |
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)