Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many NPE when hover or refactor inside "instanceof" block #3263

Open
jukzi opened this issue Nov 6, 2024 · 6 comments
Open

Many NPE when hover or refactor inside "instanceof" block #3263

jukzi opened this issue Nov 6, 2024 · 6 comments
Assignees
Labels
bug Something isn't working regression Something was broken by a previous change

Comments

@jukzi
Copy link
Contributor

jukzi commented Nov 6, 2024

package p;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class Test {
	{
		Map<String,Collection<Object>> binaryLocationsJars=new HashMap<>();
		if (null instanceof Object jar) {
				binaryLocationsJars.compute("", (pp,me // hover "me", or refactor "me"
						) ->{
					return me;
				});
		}
	}
}

for example

java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.lookup.TypeBinding.signableName()" because "binding.type" is null
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptLocalVariable(SelectionRequestor.java:418)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:1351)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1041)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:403)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:393)
	at org.eclipse.jdt.internal.debug.ui.JavaDebugHover.resolveElement(JavaDebugHover.java:519)
	at org.eclipse.jdt.internal.debug.ui.JavaDebugHover.getHoverInfo2(JavaDebugHover.java:302)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:130)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:89)
	at org.eclipse.jface.text.TextViewerHoverManager$1.run(TextViewerHoverManager.java:155)

@jukzi jukzi added bug Something isn't working regression Something was broken by a previous change labels Nov 6, 2024
@srikanth-sankaran srikanth-sankaran self-assigned this Nov 6, 2024
@srikanth-sankaran srikanth-sankaran added this to the 4.34 milestone Nov 6, 2024
@srikanth-sankaran
Copy link
Contributor

Thanks @jukzi - I'll take a look - Since this is tagged as a regression, do you know the last version where this worked ?

@jukzi
Copy link
Contributor Author

jukzi commented Nov 7, 2024

Sorry, don't know. Don't even proofed it ever worked. "regression" is only a guess in this case because i can not remember to ever had a problem there.

jukzi pushed a commit to jukzi/eclipse.jdt.ui that referenced this issue Nov 8, 2024
jukzi pushed a commit to eclipse-jdt/eclipse.jdt.ui that referenced this issue Nov 8, 2024
noopur2507 pushed a commit to eclipse-jdt/eclipse.jdt.ui that referenced this issue Nov 27, 2024
@jukzi
Copy link
Contributor Author

jukzi commented Jan 8, 2025

Still an issue! Refactoring (ALT+SHIFT+R) "me" became even worse, now logging tons of Exceptions:

image

@srikanth-sankaran srikanth-sankaran modified the milestones: 4.34, 4.35 M2 Jan 8, 2025
@srikanth-sankaran
Copy link
Contributor

The recovered parse tree is:

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class Test {
  {
    Map<String, Collection<Object>> binaryLocationsJars;
    {
      <SelectionOnArgumentName:me>;
    }
  }
  public Test() {
  }
}

We don't even recognize me to be a lambda parameter. So the elided type of the local is unresolved and null resulting in NPE.

@srikanth-sankaran srikanth-sankaran removed this from the 4.35 M2 milestone Jan 10, 2025
@srikanth-sankaran srikanth-sankaran added regression Something was broken by a previous change and removed regression Something was broken by a previous change labels Jan 10, 2025
@srikanth-sankaran
Copy link
Contributor

Sorry, don't know. Don't even proofed it ever worked. "regression" is only a guess in this case because i can not remember to ever had a problem there.

A random pick of 4.20 shows we don't NPE there, so it is a regression although I don't know exactly since when

@srikanth-sankaran
Copy link
Contributor

This is likely a bit involved, I will revisit when I have time ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Something was broken by a previous change
Projects
None yet
Development

No branches or pull requests

2 participants