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 241200 - Lambda expression that returns the input param will hint it as an unused param
Summary: Lambda expression that returns the input param will hint it as an unused param
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Mac OS X
: P4 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-30 23:11 UTC by brettryan
Modified: 2016-07-07 07:40 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description brettryan 2014-01-30 23:11:41 UTC
Given a lambda expression that simply returns its input, the editor hints that this parameter is unused.

Given the following example the `collect` method returns a `Collectors.toMap` mapper who returns the input string for the key, the editor will warn that `str' is unused, which in fact it is.

    Map<String, Integer> stringLengths
            = Collections.<String>emptySet().stream()
            .collect(Collectors.toMap(
                            str -> str,
                            str -> str.length()
                    ));

Changing this to an explicit return within a lambda block will prevent the warning.

    Map<String, Integer> stringLengths
            = Collections.<String>emptySet().stream()
            .collect(Collectors.toMap(
                            str -> { return str; },
                            str -> str.length()
                    ));

IMHO any input parameter to a lambda expression should be excluded from this rule as sometimes you may not use one of the input parameters.



Product Version: NetBeans IDE Dev (Build 201401280001)
Java: 1.7.0_51; Java HotSpot(TM) 64-Bit Server VM 24.51-b03
Runtime: Java(TM) SE Runtime Environment 1.7.0_51-b13
System: Mac OS X version 10.9.1 running on x86_64; UTF-8; en_AU (nb)
User directory: /Users/bryan/Library/Application Support/NetBeans/dev
Cache directory: /Users/bryan/Library/Caches/NetBeans/dev
Comment 1 Martin Balin 2016-07-07 07:15:46 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 2 brettryan 2016-07-07 07:40:13 UTC
Thanks Martin, it appears the whole hint isn't even available anymore. I didn't even realise it was removed.

I did often think to myself why the IDE wasn't hinting me about arguments I wasn't using in methods.

What happened to this hint? It was actually useful, just not in the context of lambda methods.