Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 423585 - [1.8][quick fix] Incorrect quick fixes suggested for code containing lambda expressions
Summary: [1.8][quick fix] Incorrect quick fixes suggested for code containing lambda e...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 423574 423582
Blocks:
  Show dependency tree
 
Reported: 2013-12-09 07:12 EST by Noopur Gupta CLA
Modified: 2020-03-18 16:28 EDT (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 Noopur Gupta CLA 2013-12-09 07:12:31 EST
package test;

import java.util.function.Supplier;

public class Bug {

	private void fun1() {
		Runnable runnable = () -> { System.out.println("hi"); };
		foo((x) -> runnable); // Error [1]
		bar(() -> runnable); // Error [2]
	}
	
	private void foo(String c) {}
	private void bar(L c) {}
}

interface L {
	int fx(int x);
}
----------------------------------------------------------------

Consider the above example having 2 compilation errors at the locations [1] and [2]. Hover over the method name in the method invocation at [1] and [2].

Issue 1:  The error reported at [1] is:
"The method foo(String) in the type Bug is not applicable for the arguments ((<no type> x) -> runnable)"
--> "((<no type> x) -> runnable)" : Is this OK?

Issue 2: The quick fixes suggested at [1] are invalid and result in exceptions:

1) Change method 'foo(String)' to 'foo((<no type> x) -> runnable)' :
java.lang.UnsupportedOperationException
	at org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding.getPackage(PolyTypeBinding.java:33)
	at org.eclipse.jdt.core.dom.TypeBinding.getQualifiedName(TypeBinding.java:814)
	at org.eclipse.jdt.core.dom.rewrite.ImportRewrite.getRawQualifiedName(ImportRewrite.java:1001)
	at org.eclipse.jdt.core.dom.rewrite.ImportRewrite.addImport(ImportRewrite.java:720)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.ChangeMethodSignatureProposal.modifyParameters(ChangeMethodSignatureProposal.java:217)
...

2) Create method 'foo((<no type> x) -> runnable)' :
java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding
	at org.eclipse.jdt.core.dom.TypeBinding.getInterfaces(TypeBinding.java:501)
	at org.eclipse.jdt.internal.ui.text.correction.ASTResolving.collectRelaxingTypes(ASTResolving.java:1000)
	at org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getRelaxingTypes(ASTResolving.java:994)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.NewMethodCorrectionProposal.evaluateParameterType(NewMethodCorrectionProposal.java:260)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.NewMethodCorrectionProposal.addNewParameters(NewMethodCorrectionProposal.java:239)
...

Issue 3: The quick fix suggested at [2] is invalid:
- Create method 'bar(L)'
Comment 1 Markus Keller CLA 2013-12-09 10:20:24 EST
> Issue 1:  The error reported at [1] is:
> "The method foo(String) in the type Bug is not applicable for the arguments
> ((<no type> x) -> runnable)"
> --> "((<no type> x) -> runnable)" : Is this OK?

It's not super pretty, but the "<no type>" part could actually help the user understand the problem. We might take that up later when the rest of the infrastructure is done and we have the final set of error messages.

> Issue 2: The quick fixes suggested at [1] are invalid and result in
> exceptions:
> 
> 1) Change method 'foo(String)' to 'foo((<no type> x) -> runnable)' :
> java.lang.UnsupportedOperationException
> 	at
> org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding.
> getPackage(PolyTypeBinding.java:33)

That's bug 423574.

> 2) Create method 'foo((<no type> x) -> runnable)' :
> java.lang.ClassCastException:
> org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding cannot be cast to
> org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding
> 	at org.eclipse.jdt.core.dom.TypeBinding.getInterfaces(TypeBinding.java:501)
> 	at
> org.eclipse.jdt.internal.ui.text.correction.ASTResolving.
> collectRelaxingTypes(ASTResolving.java:1000)

I've added a note to bug 423582.
Comment 2 Eclipse Genie CLA 2020-03-18 16:28:40 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.