This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 248476 - Propose change type fix on incompatible lambda type
Summary: Propose change type fix on incompatible lambda type
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-07 05:59 UTC by skomisa
Modified: 2015-10-05 11:40 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description skomisa 2014-11-07 05:59:26 UTC
Summary 
=======
If there is a type mismatch between a Predicate type and the lambda expression assigned to it, the error is correctly reported but the proposed hint is incorrect, and does nothing.


Steps to reproduce
==================
[1] Create a trivial Java application named TestPredicate as follows:

package testpredicate;
import java.util.function.Predicate;

public class TestPredicate {

    public static void main(String[] args) {
        Predicate<Integer> gt30 = i -> i > 30;
        Predicate<Integer> gt40 = (i) -> i > 40;
        Predicate<Integer> gt50 = (Integer i) -> i > 50;
        Predicate<Integer> gt60 = (Short i) -> i > 60;
    }
}

[2] Compile the code. The only error is on the final line of code, where the type of the Predicate (Integer) does not match the parameter type of the lambda expression (Short).

[3] The error is correctly reported by the compiler: error: "incompatible types: incompatible parameter types in lambda expression".

[4] Press alt-enter on the failing line. The hint proposed is "Change type of gt60 to Predicate<Integer>". This is exactly what the code already shows, and accepting the hint does nothing.

[5] It would be more useful if two hints were offered, to make the generic type of the Predicate match the type of the lambda argument, or vice versa. In this example those hints might be:
Hint 1: "Change type of gt60 to Predicate<Short>"
Hint 2: "Change type of lambda argument to Integer"


Environment
===========
Product Version: NetBeans IDE 8.0.1 (Build 201408251540)
Updates: NetBeans IDE is updated to version NetBeans 8.0.1 Patch 1.1
Java: 1.8.0_25; Java HotSpot(TM) 64-Bit Server VM 25.25-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b18
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\JohnDoe\AppData\Roaming\NetBeans\8.0.1
Cache directory: C:\Users\JohnDoe\AppData\Local\NetBeans\Cache\8.0.1
Comment 1 Svata Dedic 2015-04-24 15:01:58 UTC
I cowardly admit that I am unable to compute (or have the javac to compute for me) the correct type of either the lambda's parameters or the compatible outcome type.

So I'll disable the fix in this situation until a way how to get the correct type is found.

Lahvaci - could you help, please ?

fix removed in jet-main#558d88ea1485; turning to enhancement
Comment 2 Quality Engineering 2015-05-12 03:26:34 UTC
Integrated into 'main-silver', will be available in build *201505120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/558d88ea1485
User: Svata Dedic <sdedic@netbeans.org>
Log: #248476: cowardly disabled hint when lambda is assigned to a variable