apache / apache/netbeans

Incorrect type inference for Assign Return Value To New Variable

Open
#9,159 0 comments 0 reactions 0 assignees View on GitHub
Java kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 28

### What happened

Assign Return Value To New Variable in some cases yields code that doesn't compile due to type errors. See the example below.

### Language / Project Type / NetBeans Component

Java, Hints

### How to reproduce

Example:
```java
List list = Collections.emptyList();
list.stream().collect(Collectors.groupingBy(CharSequence::toString));
```
Performing "Assign Return Value To New Variable" on the collect() call results in:
```java
Map> collect = list.stream().collect(Collectors.groupingBy(CharSequence::toString));
```
However, this is incorrect and doesn't compile.

A correct result would be:
```java
Map> collect = list.stream().collect(Collectors.groupingBy(CharSequence::toString));
```
Maybe wildcard captures aren't considered correctly.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows

### JDK

NetBeans runs on JDK 21, the project is JDK 17

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start with the Java Hints implementation behind “Assign Return Value To New Variable” and reproduce the supplied stream and groupingBy example. Trace how the collect() result type is inferred, then verify that the generated declaration accounts for wildcard captures and compiles as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.